What does the ‘tearoff’ attribute do in a Tkinter Menu?
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy task.
- Menu is used to create various types of menus such as top level, pull down etc.. in Tkinter. The Top Level Menu, which is displayed under the title bar of main window.
To create menu
menubar = Menu(root)
To add text in Menu
file = Menu(menubar) menubar.add_cascade(label ='Your Text', menu = file)
- A Tearoff permits you to detach menus for the most window making floating menus. If you produce a menu you may see dotted lines at the top after you click a top menu item. To fix this tearoff needs to set to 0 at the time of menu declaration.
file = Menu(menubar,tearoff=0) edit = Menu(menubar,tearoff=0) help_ = Menu(menubar,tearoff=0)
- Cascade is used to create Sub-menus below the Main-menu.
- A submenu is a menu plugged into another menu object. By adding the menu to the fileMenu and not to the menubar, we create a submenu.
Object_Name.add_command(label ='Write Text')
- Import module
- Create normal Tkinter window
- Add Menus
- Add SubMenus
Without Using tearoff method
With tearoff method