The Menu widget in Tkinter is used to create Menu Bars in the navigation bar of an application. It is located at the top of the application window before the title bar. Sometimes, we see a dashed line which appear at the top of the first Menu Item. The tearoff(boolean) attribute in Menu specifies that if we start inserting the Menu item, then initially all the items get indexing from 1. However, when we turn off the tearoff property, the item can start its indexing from 0 and the dashed line will disappear from the top.
Example
# Import the tkinter library from tkinter import * # Create an instance of tkinter frame win= Tk() # Set the size of the Tkinter window win.geometry("700x350") # Create an instance of MenuBar menubar= Menu(win) file= Menu(menubar, tearoff= 0) # Add Menu Items file.add_command(label= "New") file.add_command(label= "Open") file.add_command(label="Save") file.add_separator() file.add_command(label= "Quit") menubar.add_cascade(label="File", menu=file) win.config(menu=menubar) win.mainloop()
Output
Running the above code will display a window with a Menu on the Navigation bar. When we click the Menu, it will display a list of Menu-items.