I have a tkinter subwindow and i am trying to call a function and use a variable to add to the number of rows of elements. When execute the button, it says that the variable is referenced before assignment. Not understanding why.
The variable is ‘plant_rows’
try to excuse my horrible programming as much as possible as im still learning.
def open_plant_window():
plant_rows = 1
def add_another_plant(window):
plant_rows = plant_rows + 1
rows_and_cols = window.grid_size()
print(rows_and_cols)
new_name = 'p' + str(plant_rows) + '_name'
print(new_name)
Entry(window).grid(row=plant_rows, column=0)
plant_window = Toplevel()
plant_window.title('Plant Selection')
plant_window.geometry('500x500')
plant_window_title = Label(plant_window, text='Add Plants').grid(row=0)
add_row = Button(plant_window, text='Add Another Plant', command=lambda: add_another_plant(plant_window)).grid(row=4)