[英]Why isn't the menu showing up? - Tkinter
I'm trying to do a menu using tkinter.我正在尝试使用 tkinter 做一个菜单。 But when I run the code, the window appears, but the menu doesn't.
但是当我运行代码时,出现了 window,但菜单没有。 I'm getting no errors.
我没有错误。
Here is my code:这是我的代码:
from tkinter import *
root = Tk()
root.geometry("500x300")
menu = Menu(root)
file_menu = Menu(menu, tearoff=0)
file_menu.add_command(label="New")
file_menu.add_command(label="Open")
file_menu.add_command(label="Save")
menu.add_cascade(label="File", menu=file_menu)
menu
root.mainloop()
You haven't added it to the root window.您尚未将其添加到根 window。 You need to do the following after creating
menu
:创建
menu
后,您需要执行以下操作:
root.configure(menu=menu)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.