Python | Menu widget in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself.
Menus are the important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipulating data. Toplevel menus are displayed just under the title bar of the root or any other toplevel windows.
menu = Menu(master, **options)
Below is the implementation:
# importing only those functions # which are needed from tkinter import * from tkinter.ttk import * from time import strftime # creating tkinter window root = Tk() root.title('Menu Demonstration') # Creating Menubar menubar = Menu(root) # Adding File Menu and commands file = Menu(menubar, tearoff = 0) menubar.add_cascade(label ='File', menu = file) file.add_command(label ='New File', command = None) file.add_command(label ='Open...', command = None) file.add_command(label ='Save', command = None) file.add_separator() file.add_command(label ='Exit', command = root.destroy) # Adding Edit Menu and commands edit = Menu(menubar, tearoff = 0) menubar.add_cascade(label ='Edit', menu = edit) edit.add_command(label ='Cut', command = None) edit.add_command(label ='Copy', command = None) edit.add_command(label ='Paste', command = None) edit.add_command(label ='Select All', command = None) edit.add_separator() edit.add_command(label ='Find...', command = None) edit.add_command(label ='Find again', command = None) # Adding Help Menu help_ = Menu(menubar, tearoff = 0) menubar.add_cascade(label ='Help', menu = help_) help_.add_command(label ='Tk Help', command = None) help_.add_command(label ='Demo', command = None) help_.add_separator() help_.add_command(label ='About Tk', command = None) # display Menu root.config(menu = menubar) mainloop() |
Output:



Note: In above application, commands are set to None but one may add different commands to different labels to perform the required task.
Recommended Posts:
- Progressbar widget in Tkinter | Python
- Python | PanedWindow Widget in Tkinter
- Tkinter | Adding style to the input text using ttk.Entry widget
- Python | Switch widget in Kivy
- Python | Popup widget in Kivy
- Python | BoxLayout widget in Kivy
- Python | Progress Bar widget in kivy
- Python | Textinput widget in kivy
- Python | Scrollview widget in kivy
- Python | Add image widget in Kivy
- Python | Slider widget in Kivy
- Python | Slider widget using .kv file
- Python | Spinner widget in kivy
- Python | Carousel Widget In Kivy
- Python | Checkbox widget in Kivy
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



