Tkinter OptionMenu Get option content
The option content can be obtained using the get() method.
Example#1
Get the contents of the OptionMenu’s current options. This program provides the Print button, which can be clicked to list the selected contents in the Python Shell window.
from tkinter import *
def printSelection():
print("The selection is : ",var.get())
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
omTuple = ("Python","Java","C") # Use Tuple
# omTuple = ["Python","Java","C"] # Use List
var = StringVar(root)
var.set("Python")
optionmenu = OptionMenu(root,var,*omTuple)
optionmenu.pack(pady=10)
btn = Button(root,text="Print",command=printSelection)
btn.pack(pady=10,anchor=S,side=BOTTOM)
root.mainloop()
Output: