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

Rob W. W. Hooft rob at
Mon Apr 3 02:17:47 EDT 2000

>>>>> "FL" == Fredrik Lundh <effbot at> writes:

 FL> 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?

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

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

 FL>     root = widget.winfo_toplevel()

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

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

Hm. Except that my Toplevel windows are often nested deeply, and
certainly not restricted to children of the root! I think that your
approach is distinctly different from _root() except if you severely
restrict your toplevel window creation.


=====   rob at  =====
=====   R&D, Nonius BV, Delft             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========

More information about the Python-list mailing list