tkinter - Set Python OptionMenu by index -


i'm trying set value in optionmenu index of options, , not use actual option value itself.

for example, if optionmenu has options ["one", "two", "three"], want able set "one" writing my_option_menu.set(options[0]), not my_option_menu.set("one")

the optionmenu dynamically populated list depending on 2 other optionmenus set to, why want refer options index , not actual value. optionmenu object have way return list of options populated options[0] method above work?

thanks.

the simplest way keep copy of list used define optionmenu. can use index value list , assign associated variable.

for example:

options = ["one","two","three"] ... self.menuvar = tk.stringvar(master) self.optionmenu = tk.optionmenu(master, self.menuvar, *options) ... self.menuvar.set(options[0]) 

another option menu object associate widget, , use menu commands text @ given index, , use set variable:

value = self.optionmenu["menu"].entrycget(0, "label") self.menuvar.set(value) 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -