简体   繁体   English

使用 tkinter 在 python 中创建菜单时出错

[英]Error while creating the menu in python using tkinter

As you can see, whenever I'm going to run the code, there is an error shows like this( _tkinter.TclError: unknown option "-Label" ) what is the problem with the Label function?如您所见,每当我要运行代码时,都会显示如下错误( _tkinter.TclError: unknown option "-Label" )Label function 有什么问题?

from tkinter import *
    
def donothing():
    print("It's just an example")
    
window = Tk()
    
menu = Menu(window)
window.config(menu=menu)
    
submenu = Menu(menu)
menu.add_cascade(Label="File", menu=submenu)
submenu.add_command(Label="New File", command=donothing)
submenu.add_command(Label="Save", command=donothing)
submenu.add_command(Label="Save As", command=donothing)
submenu.add_separator()
submenu.add_command(Label="Exit", command=donothing)
    
submenu2 = Menu(menu)
submenu2.add_cascade(Label="Edit", menu=submenu2)
submenu2.add_command(Label="Undo", command=donothing)
    
window.mainloop()

You might be looking for this你可能正在寻找这个

from tkinter import *
    
def donothing():
    print("It's just an example")
    
window = Tk()
    
menu = Menu(window)
window.config(menu=menu)
    
submenu = Menu(menu,tearoff=False)
menu.add_cascade(label="File", menu=submenu)
submenu.add_command(label="New File", command=donothing)
submenu.add_command(label="Save", command=donothing)
submenu.add_command(label="Save As", command=donothing)
submenu.add_separator()
submenu.add_command(label="Exit", command=donothing)
    
submenu2 = Menu(menu)
submenu2.add_cascade(label="Edit", menu=submenu2)
submenu2.add_command(label="Undo", command=donothing)
    
window.mainloop()

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

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