Python Tkinter菜单显示

Python Tkinter菜单显示,python,tkinter,tkinter-menu,Python,Tkinter,Tkinter Menu,我不熟悉使用Tkinter,我正在尝试创建菜单,但它不会显示,即使我认为我已经完成了操作。 我真的不知道错过了什么 from tkinter import * root=Tk() root.wm_title("Tkiner GUI Test") def hello(): print("Hello World!") menubar = Menu(root) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label=

我不熟悉使用Tkinter,我正在尝试创建菜单,但它不会显示,即使我认为我已经完成了操作。
我真的不知道错过了什么

from tkinter import *

root=Tk()
root.wm_title("Tkiner GUI Test")

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

menubar = Menu(root)

filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=hello)
filemenu.add_command(label="Save", command=hello)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)


editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=hello)
editmenu.add_command(label="Copy", command=hello)
editmenu.add_command(label="Paste", command=hello)
menubar.add_cascade(label="Edit", menu=editmenu)

helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)

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

root.mainloop()
运行此代码时,我只看到一个没有菜单的空窗口。

在OSX上,菜单栏与OSX中所有其他应用程序的菜单栏一样显示在屏幕顶部。它不会出现在窗口顶部。

我不知道为什么它对您不起作用。我在Linux和Windows上使用Python3.6,这对我来说是一个突破。我不敢相信我错过了:)