Python 3 Tkinter选项菜单

2024-10-01 19:15:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在四处搜索,但在Tkinter中找不到OptionMenu语法的正确解释。你知道吗

如何在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")

Tags: selftkinterdef选项语法frametkdrop
1条回答
网友
1楼 · 发布于 2024-10-01 19:15:43

要获取OptionMenu的值,需要获取关联变量的值。在您的情况下:

homeTeamName.get()

如果要通过command执行此操作,必须将选项设置为对函数的引用:

drop = OptionMenu(...command=func)

相关问题 更多 >

    热门问题