[Tkinter-discuss] Working with tear-off menus (change the "-----" label, customize location/appearance of tear-off window)

python at bdurham.com python at bdurham.com
Mon Nov 22 21:30:11 CET 2010


Hi Michael,

Thank you for your help. Your solution works well (tested under Windows
7 with 32-bit Python 2.7).

Regards,
Malcolm


<snipped>
> 2. Is there a way to customize the location and appearance of the
> window that contains a tear-off menu? On Windows, the tear-off
> menus appear at random(?) places on the desktop. And these
> windows have min/max buttons and are resizable - all behaviors
> that IMO don't make sense for a floating tear-off menu. What I
> would like to do is capture a reference to the window of a
> tear-off and customize it like I would any other Toplevel()
> window. Is this possible?

Here on linux (I guess it should be the same on windows) the
tearoffcommand takes two arguments, first the menu itself and second the
newly created toplevel window, both as strings however, and Tkinter
doesn't know about the toplevel, so you will have to use the tcl-syntax
again :(

See this example:

from Tkinter import *
root = Tk()

def foo(menu, top):
    root.nametowidget(menu).add_command(label='baz')
    root.tk.call('wm', 'resizable', top,  '0', '0')

m = Menu(root, tearoffcommand=foo)
m.add_command(label='foo')
m.add_command(label='bar')
m.add_command(label='blah')

root.bind('<3>', lambda event: m.tk_popup(event.x_root, event.y_root))

root.mainloop()

</snipped>


More information about the Tkinter-discuss mailing list