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


_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to