Tkinter 菜单栏

Tkinter Menubar

我刚开始学习 Tkinter,在制作菜单栏时遇到了问题,因为附有错误和代码。提前致谢。

from tkinter import *

root = Tk()
root.title("HP SIMPLE FINANCE")

w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))

def donothing():
    pass

menubar = Menu(root)
root.config(menu=menubar)

filemenu = Menu(menubar)
menubar.add_cascade(label="File", Menu=filemenu)
filemenu.add_command(label="Open Portfolio file", command=donothing)
filemenu.add_command(label="New Portfolio", command=donothing)
filemenu.add_command(label="Reports", command=donothing)
filemenu.add_command(label="Restore from backup", command=donothing)
filemenu.add_command(label="Exit", command=root.quit)

root.mainloop()
File "F:/Finance software/Main window.py", line 28, in <module>
    menubar.add_cascade(label="File", Menu=filemenu)
  File "C:\Users\harshparmar\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3289, in add_cascade
    self.add('cascade', cnf or kw)
  File "C:\Users\harshparmar\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3284, in add
    self.tk.call((self._w, 'add', itemType) +
_tkinter.TclError: unknown option "-Menu"

进程已完成,退出代码为 1

替换

menubar.add_cascade(label="File", Menu=filemenu)

menubar.add_cascade(label="File", menu=filemenu)