469,628 Members | 1,016 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

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

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

Apr 6 '06 #1
2 2626
On Thu, 2006-04-06 at 12:27 -0700, ishtar2020 wrote:
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

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Apr 6 '06 #2
In article <11**********************@g10g2000cwb.googlegroups .com>,
ishtar2020 <is********@hotmail.com> wrote:
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/Coo.../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.

--
Jim Segrave (je*@jes-2.demon.nl)

Apr 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Patrick L. Nolan | last post: by
reply views Thread by Humpty Dumpty | last post: by
1 post views Thread by eltronic | last post: by
3 posts views Thread by John Pote | last post: by
5 posts views Thread by Phil Schmidt | last post: by
5 posts views Thread by Kevin Walzer | last post: by
3 posts views Thread by MartinRinehart | last post: by
8 posts views Thread by karthikbalaguru | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.