I’ve written this code which makes one entry box appear on a new row when the button is pressed, but I’m not sure how to get it to make a new entry on a new row underneath the last one. My main problems are how to increment a row_number variable within the function without re-setting it every time the function is called, and how to make the function give a new name to the “new_entry” object each time it is called so that it doesn’t overwrite itself.
def new_row():
#Create widgets
new_entry = ttk.Entry(root, width=7)
#Put widgets in grid
new_entry.grid(column=0, row=2, sticky=(W, E))
root = Tk()
createRow_button = ttk.Button(root, text='New Row', command=new_row)
createRow_button.grid()
root.mainloop
This is the first time I’ve asked a question on Stack Overflow so sorry if I’ve got anything wrong.
Use a class and store the number of rows as class attribute,
self.num_rows: