I am try to use a OptionMenu in my GUI, I am unable to get the value of selected item in OptionMenu.I am unable to write the function properly.
Following is my code.
from tkinter import *
root = Tk()
variable = StringVar(root)
options = {"one": 1, "two": 2, "three": 3}
O_menu = OptionMenu(root, variable, *options.keys()).pack()
def sample():
#here i want to write a function so that when I select "one", the result should print 1.
pass
bu = Button(root, text="print", command=sample).pack()
root.mainloop()
Additionally I want OptionMenu with default value of one
to be selected when I start the GUI.