Tkinter: "Get root for a widget" is private?

Fredrik Lundh effbot at
Sun Apr 2 11:16:32 CEST 2000

Randall Hopper wrote:
> I have a widget and want to retrieve the root.  I see the _root() method,
> but by Python convention, isn't this method private?
> Should users of Tkinter be calling this?

as long as nobody calls the Tkinter police, you're safe.

however, using the *toplevel* rather than the actual root
object is usually sufficient:

    root = widget.winfo_toplevel()

to get from the toplevel to the real root, just add:

    if root.master:
        root = root.master # real root


More information about the Python-list mailing list