Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Tkinter - OptionMenu Widget
Next article icon
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:Python3 1==
# importing only  those functions# which are neededfromtkinterimport*fromtkinter.ttkimport*fromtimeimportstrftime# creating tkinter windowroot=Tk()root.title('Menu Demonstration')# Creating Menubarmenubar=Menu(root)# Adding File Menu and commandsfile=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 commandsedit=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 Menuhelp_=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 Menuroot.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.

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp