Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the 'tearoff' attribute do in a tkinter Menu?

I often see Tkinter applications initialize Menu widgets using tearoff=0 in the constructor.

import tkinter as tk

root = tk.Tk()
menubar = tk.Menu(root)    
filemenu = tk.Menu(menubar, tearoff=0)

effbot.org's documentation for Menu specifies that the default value for tearoff is 1, but it doesn't explain what the value is used for.

tearoff=
    Default value is 1. (tearOff/TearOff)
tearoffcommand=
    No default value. (tearOffCommand/TearOffCommand)

What does the tearoff attribute do when initializing a tkinter Menu widget?

like image 280
Stevoisiak Avatar asked Mar 26 '18 18:03

Stevoisiak


People also ask

What is tkinter menu?

The tkinter menu is a top-level pulldown menu. They are shown just under the title bar, as you'd expect from traditional gui apps. The menu can have multiple sub menus and each sub menu can contain items. Menu items can be associated with callback methods, meaning when you click them a Python method is called.


1 Answers

The official python docs admit that they're a little light on details:

The tkinter package is a thin object-oriented layer on top of Tcl/Tk. To use tkinter, you don’t need to write Tcl code, but you will need to consult the Tk documentation, and occasionally the Tcl documentation.

The Tk documentation for tearoff gives you what you're looking for:

tearoff allows you to detach menus for the main window creating floating menus. If you create a menu you will see dotted lines at the top when you click a top menu item. If you click those dotted lines the menu tears off and becomes floating.

like image 179
Darrick Herwehe Avatar answered Oct 19 '22 22:10

Darrick Herwehe