I've written some code which creates a given number of entry boxes depending on user inputs. Name entry boxes are a given but each name_input
entry box has an optional vname_input
entry either side.
I would like the user to be able to delete or deactivate any specific vname_input
entry box by checking its corresponding checkbox.
Currently checking any of the checkboxes removes the last entry rather than the given entry. I believe the poblem is indexing the correct entry within the checkbox command but I'm not sure how I would do this..
Here's my code:
p = 0
vname = []
name = []
for i in range(given_entry_count):
vname_input = Entry(build_labelframe, width=20)
vname_input.grid(row=6 + p + i, column=0) # p & i update position
vname.append(vname_input) # Stores entry box ID
name_input = Entry(build_labelframe, width=20)
name_input.grid(row=7 + p + i, column=0)
name.append(name_input)
def remove_vname_command():
vname[].grid_forget()
remove_vname_tick = Checkbutton(build_labelframe, text="Remove veil",
bd=0, command=remove_veil_command) # Function for removing entries
remove_vname_tick.grid(row=6 + p + i, column=1)
p += 2
vname_input = Entry(build_labelframe, width=20)
vname_input.grid(row=6 + p + i, column=0) # Places final optional vname entry
vname.append(vname_input)
Aucun commentaire:
Enregistrer un commentaire