[Tkinter-discuss] Dealing with a Tk reference

Michael Lange klappnase at web.de
Sun Sep 4 10:38:35 EDT 2016


Hi,

On Sun, 4 Sep 2016 10:56:20 -0300
Cam Farnell <msa01 at bitflipper.ca> wrote:

(...)
> 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.

to convert the widget name into a Widget object you will need the
nametowidget method, as in

menubar = top.nametowidget(top['menu'])

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No one may kill a man.  Not for any purpose.  It cannot be condoned.
		-- Kirk, "Spock's Brain", stardate 5431.6


More information about the Tkinter-discuss mailing list