I'm trying to set my Tkinter OptionMenu's after loading a file, but I can't get the options to change. I have looked through many websites but none their code works. Does anyone know how to change a Tkinter OptionMenu's drop-down values after its been created?
Here is some sample code:
Okay so I'm trying to dynamically set new options in the OptionMenu for the user every time the user loads a new file. The host_selection.children['menu'] does not work. I found that on another site. It throws a KeyError when I try to run it.Code:from tkinter import * root = Tk() root.title("My Program") root.geometry("400x200") root.resizable(0,0) host_options = StringVar(root) host_options.set('EMPTY') host_selection = OptionMenu(root, host_options) host_selection.config(width=15) host_selection.pack(side=TOP, pady=(0, 10)) option = host_selection.children['menu'] root.mainloop()
How do you change an OptionMenu's options after its been created?