简体   繁体   English

Tkinter 菜单栏

[英]Tkinter Menubar

I just started learning Tkinter and had an issue in making the menu bar as the error and code attached.我刚开始学习 Tkinter 并且在将菜单栏设置为错误和附加代码时遇到了问题。 Thanks in advance.提前致谢。

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"

Process finished with exit code 1进程以退出代码 1 结束

replace代替

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM