Unposting tearoff menus under win32...

Rod Stephenson mrstephenson at dof.se
Sun Apr 14 00:22:51 EDT 2002


I'm using Tkinter and the tearoff menu feature. However in certain
situations I'd like the torn-off menu to go away without user
interaction. 

Using Tk I can say 
	winfo children .kMain
where .kMain is the toplevel window, and get something like

.kMain.menubar .kMain.#kMain#menubar .... .kMain.tearoff1 .kMain.tearoff2

with .kMain.tearoff1  and .kMain.tearoff2 being a couple of tornoff
menus; I can then destroy these directly. 

Trying this under Tkinter I get an exception: 
root=Tk()
...
print root.winfo_children()
.....
  File "C:\PYTHON22\lib\lib-tk\Tkinter.py", line 609, in winfo_children
    self.tk.splitlist(self.tk.call(
  File "C:\PYTHON22\lib\lib-tk\Tkinter.py", line 979, in nametowidget
    w = w.children[name]
KeyError: #11512128

which I assume has something to do with the Tkinter naming convention
for menus. If I use root.children instead I get a list of the
children, but the same list whether or not the tearoff menus are
posted. I assume this means that in Tkinter they are implemented as
children of some other (non toplevel) widget, but I'm still trying to
track this down.

Back to the main task (just getting rid of the tearoff), is there
another way to accomplish this? unpost() apparently doesnt work under
win32. Any insights appreciated...

Thanks

Rod Stephenson





More information about the Python-list mailing list