TKinter OptionMenu: How to get the selected choice? TKinter OptionMenu: How to get the selected choice? tkinter tkinter

TKinter OptionMenu: How to get the selected choice?


The OptionMenu has a built in command option, which gives the current state of the menu to a function. See this:

#!/usr/bin pythonimport sysfrom Tkinter import *# My frame for formclass simpleform_ap(Tk):    def __init__(self,parent):        Tk.__init__(self,parent)        self.parent = parent        self.initialize()        self.grid()    def initialize(self):        # Dropdown Menu        optionList = ["Yes","No"]        self.dropVar=StringVar()        self.dropVar.set("Yes") # default choice        self.dropMenu1 = OptionMenu(self, self.dropVar, *optionList,                                    command=self.func)        self.dropMenu1.grid(column=1,row=4)    def func(self,value):        print valuedef create_form(argv):    form = simpleform_ap(None)    form.title('My form')    form.mainloop()if __name__ == "__main__":    create_form(sys.argv)

This should do what you wish.