2016-11-27 109 views
0

我一直在四處搜尋,我無法找到Tkinter中OptionMenu語法的正確解釋。Python 3 Tkinter OptionsMenu

我將如何獲得OptionMenu中當前選擇的選項?

def homeTeamOption(self, frame, sortedList): 

    def func(): 
     print(homeTeamName) 
     return 

    homeTeam = tk.StringVar(frame) 
    returnValueAwayTeam = [] 

    options = sortedList 
    homeTeamName = tk.StringVar() 
    drop = OptionMenu(frame, homeTeamName, *options, command=func()) 
    drop.place(x=200, y= 100, anchor="nw") 

回答

1

要獲取OptionMenu的值,您需要獲取關聯變量的值。在你的情況將是:

homeTeamName.get() 

如果你想通過command要做到這一點,必須將選項設置爲在函數的引用:

drop = OptionMenu(...command=func)