Adding Command To A Tkinter Optionmenu?
I'm writing some code in Python 2.7.8 which includes the OptionMenu widget. I would like to create an OptionMenu that calls a function when the option is changed but I also want th
Solution 1:
There is never a need for a direct apply call, which is why is is dreprecated in 2.7 and gone in 3.0. Instead use the *seq syntax. Just combine the two things you did. The following seems to do what you want.
from tkinter import *
def func(value):
print(value)
root = Tk()
options = ["1", "2", "3"]
var = StringVar()
drop = OptionMenu(root, var, *options, command=func)
drop.place(x=10, y=10)
Post a Comment for "Adding Command To A Tkinter Optionmenu?"