Apr-06-2020, 08:06 PM
(Apr-06-2020, 05:41 PM)deanhystad Wrote: It would be *self.options, not self.*options. But that has nothing to do with your problem.
I think your "*option" reference refers to this or a similar post on stackoverflow
choices = ('network one', 'network two', 'network three') def refresh(): # Reset var and delete all old options var.set('') network_select['menu'].delete(0, 'end') # Insert list of new options (tk._setit hooks them up to var) new_choices = ('one', 'two', 'three') for choice in new_choices: network_select['menu'].add_command(label=choice, command=tk._setit(var, choice)) network_select = tk.OptionMenu(root, var, *choices)Here *choices unpacks the choices list into positional arguments so the OptionMenu command above becomes:
network_select = tk.OptionMenu(root, var, 'network one', 'network two', 'network three')But that is not going to do what you want. That only sets an initial set of choices, I don't see that OptionMenu has any kind of variable that you can bind to automatically update the list. What you need to do is the other part of the post, the "refresh()". This method would bet called when you open a spreadsheet and get a list of the sheets. It clears out the old choices and builds a new list of choices.
My god, I spent 4 hours looking for this
It was indeed as simple as adding the part below, I had never heard of tk._setit
Thanks so much!
for choice in new_choices: network_select['menu'].add_command(label=choice, command=tk._setit(var, choice))