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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With