【问题标题】:Error while creating the menu in python using tkinter使用 tkinter 在 python 中创建菜单时出错
【发布时间】:2021-04-20 17:14:32
【问题描述】:

如您所见,每当我要运行代码时, 有这样的错误显示(_tkinter.TclError: unknown option "-Label") Label 函数有什么问题?

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()

【问题讨论】:

  • 尝试将Label 更改为label

标签: python function tkinter


【解决方案1】:

你可能正在寻找这个

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-20
    • 2016-03-16
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多