2016-11-27 44 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)