macOS 上不显示菜单栏

Menu bar does not show up on macOS

我在 Pycharm (macOS) 上写了这段代码,但菜单栏没有显示。谁能告诉我为什么?

    from tkinter import *

    root = Tk()


    def hello():
        print("hello!")


   # create a toplevel menu
   menubar = Menu(root)
   menubar.add_command(label="Hello!", command=hello)
   menubar.add_command(label="Quit!", command=root.destroy)

   # display the menu
   root.config(menu=menubar)
   root.mainloop()

您不能在 OSX 中将命令放在菜单栏的最顶部。此外,菜单不会出现在 window 的顶部,它会出现在屏幕顶部,就像原生 OSX 应用程序一样。

除了您的菜单栏没有下拉菜单这一事实外,它按设计工作。添加下拉菜单,该菜单将显示在菜单栏上。