Skip to content Skip to sidebar Skip to footer

Changing The Selected Item Of An Optionmenu Programmatically

I have defined a simple OptionMenu like import Tkinter as tk optionList = ('a', 'b', 'c') v = tk.StringVar() v.set(optionList[0]) om = tk.OptionMenu(self, v, *optionList) This l

Solution 1:

You already found a way to set a default value and change it. You have the v variable associated to that OptionMenu widget. If at any time you change the value of that variable again, it will update your widget:

import tkinter as tk

root = tk.Tk()
optionList = ('a', 'b', 'c')
v = tk.StringVar()
v.set(optionList[0])  # Here is the initially selected value
om = tk.OptionMenu(root, v, *optionList)
om.pack()

v.set(optionList[2]) # This one will be the final selected value 
root.mainloop()

Post a Comment for "Changing The Selected Item Of An Optionmenu Programmatically"