Dealing with a Tk reference

Cam Farnell <[email protected]>
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>
I've been using New Mexico Tech example code from here:

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/menu-toplevel.html

to create a top-level menu. The example code is:

     top = self.winfo_toplevel()
     self.menuBar = tk.Menu(top)
     top['menu'] = self.menuBar

     self.subMenu = tk.Menu(self.menuBar)
     self.menuBar.add_cascade(label='Help', menu=self.subMenu)
     self.subMenu.add_command(label='About', command=self.__aboutHandler)

and that works just fine. In particular it creates a Menu using:

     self.menuBar = tk.Menu(top)

and then assigns it to the top-level using:

     top['menu'] = self.menuBar

In my application it is not convenient to keep the reference to the Menu in self.menuBar. Later when it comes time to add another another cascade to the menu I was hoping to be able access the menu bar using:

     menuBar = top['menu']

but in fact having done that, menuBar not a tk.Menu object as I was hoping but rather a string, such as ".3070843372L", which is presumably a reference to a tk object.

So my question is: how to use the string to access the corresponding tk.Menu object? There's probably some magic way to do that but a bunch of internet searching didn't turn it up.

Thanks

Cam
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.