tkinter顶级菜单未在macOS中显示

问题描述 投票:1回答:1

这是effbot中的经典代码,它告知:

顶级菜单显示在根目录标题栏或任何其他顶级窗口的下方(或在Macintosh上,沿着屏幕的上边缘)。要创建顶层菜单,请创建一个新的Menu实例,并使用add方法向其添加命令和其他菜单项。

但不起作用,找不到菜单。我希望在Welcome的右侧有Quitpython。有什么东西错过吗?

系统信息

  • Python 3.7.5
  • macOS Catalina
  • TkVersion 8.6
import tkinter as tk

def hello():
    print('Hi~')

root = tk.Tk()
root.title("MacOS Catalina")
menubar  = tk.Menu(root)
root.configure(menu=menubar)
menubar.add_command(label='Welcome', command=hello)
menubar.add_command(label='Quit', command=root.quit)
root.mainloop()

enter image description here

python-3.x macos tkinter menu
1个回答
0
投票

在OSX上,您不能在根菜单上放置命令。您只能放置其他菜单(级联)。例如:

© www.soinside.com 2019 - 2024. All rights reserved.