Tkinter GUI: Update choices of an option menu depending on a choice from another option menu [duplicate] Tkinter GUI: Update choices of an option menu depending on a choice from another option menu [duplicate] tkinter tkinter

Tkinter GUI: Update choices of an option menu depending on a choice from another option menu [duplicate]


An optionmenu is made up of two parts: a button and a menu. You can get these parts from the "children" attribute of the widget.

om = tk.OptionMenu(...)menu = om.children["menu"]

You can delete all of the old values in the menu with standard menu functions:

menu.delete(0, "end")

You can add new items to the menu with standard menu functions. You need to associate a command with each that sets the associated variable. So, for example, if you know the variable associated with the option menu is named "self.choice", you can do something like this:

for value in ("value1", "value2", ...):    menu.add_command(label=value, command=lambda v=value: self.choice.set(v))