How to create a tear off menu in TKinter. Help Needed

I

ishtar2020

Hi everybody

I'd appreciate some help on creating a tear off menu with TkInter. I've
been reading some documentation but still no luck.

Please don't get confused: when I mean "tear off" menu I don't mean a
drop-down or a pop-up menu, but those options which yield to another
batch of sub-options when scrolled over, (as for example, the File->New
option from internet explorer).

I'm sure TkInter supports those widgets because the IDLE editor is
built on it and it's got some tear off options like File->Recent Files.

Thank you all in advance
 
J

John McMonagle

Hi everybody

I'd appreciate some help on creating a tear off menu with TkInter. I've
been reading some documentation but still no luck.

Please don't get confused: when I mean "tear off" menu I don't mean a
drop-down or a pop-up menu, but those options which yield to another
batch of sub-options when scrolled over, (as for example, the File->New
option from internet explorer).

I'm sure TkInter supports those widgets because the IDLE editor is
built on it and it's got some tear off options like File->Recent Files.

Thank you all in advance

Are you sure you don't mean a cascading menu ? A tearoff menu gives the user the ability to tear off the menu into a new top level window.

The following example illustrates the difference:

from Tkinter import *
r = Tk()
m = Menu(r)

# Create a cascading Edit menu
editmenu = Menu(m, tearoff=0)
editmenu.add_command(label='copy')
editmenu.add_command(label='cut')
editmenu.add_command(label='paste')

# Create a sub menu of the edit menu and use tearoff option
testmenu = Menu(editmenu, tearoff=1)
testmenu.add_command(label='option1')
testmenu.add_command(label='option2')

# add the sub menu to the editmenu
editmenu.add_cascade(label='test', menu=testmenu)

# Add the edit menu to the menu bar
m.add_cascade(label='Edit', menu=editmenu)


# Display the menu
r.config(menu=m)

r.mainloop()


John McMonagle
 
J

Jim Segrave

Hi everybody

I'd appreciate some help on creating a tear off menu with TkInter. I've
been reading some documentation but still no luck.

Please don't get confused: when I mean "tear off" menu I don't mean a
drop-down or a pop-up menu, but those options which yield to another
batch of sub-options when scrolled over, (as for example, the File->New
option from internet explorer).

I'm sure TkInter supports those widgets because the IDLE editor is
built on it and it's got some tear off options like File->Recent Files.

I created an extension for Tkinter which allows for popup menus (onesl
which appear when a parent menu item is under the cursor and close if
you then move away). It was an early experiment for me with Tkinter,
so I'm sure it can be heavily improved. It's available on

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442500

(see the notes, the demonstration program doesn't work correctly on
Windows, because I forgot the directory separator is a '\'. But the
code itself works to create cascading auto-pop-up menus, or any other
widget you want to pop-up as part of a menu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top