- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a separator in Menu item in Tkinter?
The Tkinter Menu widget is used to create a dropdown menu in an application. With menu widgets, we can select an item from the menu and run a specific task in the application.
In many applications, we see a dotted separator line that separates the menu items in the menu. The separator separates the menu item of one type from another, and we can use it to visualize the hierarchy of the menu items. To create a separator among the menu items, you can use the add_separator() method.
Example
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of Tkinter frame win=Tk() # Set the geometry of the Tkinter library win.geometry("700x350") menubar=Menu(win) # Add Menu my_menu=Menu(menubar, tearoff=0) # Adding Menu Items my_menu.add_command(label="Refresh") my_menu.add_command(label="Edit") # Add a separator my_menu.add_separator() my_menu.add_command(label="View") my_menu.add_command(label="Save") my_menu.add_command(label="Close") menubar.add_cascade(label='File', menu=my_menu) win.config(menu=menubar) win.mainloop()
Output
Running the above code will display a window with a menu bar at the top of the window. Click the 'File' Menu to display the menu items in the menubar. The menu items are separated by a separator.
- Related Articles
- How to add a separator to a Menu in JavaFX?
- How to add accelerators to a menu item?
- How to add the slider to a menu item in JavaFX?
- How to add image to the menu item in JavaFX?
- How to disable a menu item in JavaFX
- How to create a Popup Menu in Tkinter?
- How to add separator in a ToolBar with Java?
- How to edit a Listbox item in Tkinter?
- How to add mnemonics to a menu in JavaFX?
- How to add a separator for a choice box in JavaFX?
- How to add a list item in HTML?
- How to insert an image in a Tkinter canvas item?
- How to change the text color of Menu item in Android?
- How to directly modify a specific item in a TKinter listbox?
- How to add an item to a list in Kotlin?

Advertisements