I'm trying to do a menu using tkinter. But when I run the code, the window appears, but the menu doesn't. 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. You need to do the following after creating menu
:
root.configure(menu=menu)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.