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

Jeff Senn senn at maya.com
Wed Apr 5 13:52:25 EDT 2000


Randall Hopper <aa8vb at yahoo.com> writes:
> Jeff Senn:
>  |Unless you're doing something wacky (creating multiple roots??), you
>  |could just do what Tkinter itself (generally) does and use
>  |Tkinter._default_root to get the instance of the root object....
> 
> Right.  I'm using _root() now which works.  My original point wasn't that I
...
> If _root() was ripped out in the next version of Python, I wouldn't have a
> leg to stand on.  And by all rights it's protected so removing it should
> not affect me (or any other external code), unless I (or it) was deriving
> off this class.

[...deriving from one of the widget class... this is a common practice, no?
So, you're probably safe anyway...]

> As Fredrik mentioned I could just snitch global Tk commands off
> any_old_widget, but an event loop timer object that has nothing to do with
> "any" widget shouldn't be keeping a handle to any_old_widget.  That's not
> clean code.

Definitely.

...
> So my request was for _root() to be declared public (e.g. as .root())

Sorry -- I missed the very beginning of the thread.  Indeed a public
Tkinter.root() (or .default_root()) seems like the best solution.

For the short run you could duplicate _root() in your own code -- it
relies only on "public" members after all ;-)

Class Misc:
...
	def _root(self):
		w = self
		while w.master: w = w.master
		return w
-- 
-Jas





More information about the Python-list mailing list