 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the 'tearoff' attribute do in a Tkinter Menu?
Using Tkinter.Menu, we can create menus and submenus. Also, there are some other properties which are used with tkinter menus.
Tearoff property makes the menus in the window as tearable. tearoff attribute accepts a Boolean value to separate the menu from the main window or the parent window. With tearoff attribute, we have two options,
- If tearoff=0, make the menu stick to the Window. 
- If tearoff=1, it display a “----” empty dotted lines on the menus through which we can separate our menu from the window. 
Example
#Importing the tkinter library from tkinter import * win= Tk() win.title("Tearoff Example") win.geometry("600x500") #Define a Function for Menu Selection Event def mytext():    lab= Label(win,text= "You have made a selection", font=('Helvetica',20)).pack(pady=20) #Create a Menubar menu_bar = Menu(win) #Make the menus non-tearable file_menu = Menu(menu_bar, tearoff=0) #Tearable Menu #file_menu= Menu(menu_bar, tearoff=1) file_menu.add_command(label="New",command=mytext) # all file menu-items will be added here next menu_bar.add_cascade(label='File', menu=file_menu) win.config(menu=menu_bar) mainloop()  Output
Running the above snippet will generate the output and will show a window which will have a menu.
Thus, for non-tearable and tearable menus (tearoff=0 and tearoff=1), the output will be as follows −


Advertisements
 