I was wondering if there is any way for me to see what the User has selected among the list displaying, let\'s say: [\"Apple\",\"Orange\",\"Grapes\"]
right after th
Trace the StringVar
.
from Tkinter import *
def option_changed(*args):
print "the user chose the value {}".format(variable.get())
print a
master = Tk()
a = "Foo"
variable = StringVar(master)
variable.set("Apple") # default value
variable.trace("w", option_changed)
w = OptionMenu(master, variable, "Apple", "Orange", "Grapes")
w.pack()
mainloop()
Here, option_changed
will be called whenever the user chooses an option from the option menu.
You can wrap the trace argument in a lambda to specify your own parameters.
def option_changed(foo, bar, baz):
#do stuff
#...
variable.trace("w", lambda *args: option_changed(qux, 23, "hello"))