Tkinter: "Get root for a widget" is private?
senn at maya.com
Wed Apr 5 15:15:19 CEST 2000
Randall Hopper <aa8vb at yahoo.com> writes:
> I have a timer class built around Tk timers. I realize I could just pass
> any_old_widget into this routine, and it would store it off into state data
> and use it periodically to access the 'after' and 'after_cancel' methods.
> However, this timer has nothing to do with this widget in particular, so
> why should it have a reference to it (versus the button next to it, or the
> list widget below it)? It makes more sense for the timer class to accept
> and bookmark the root object. This root is associated with the global Tk
> state, and it makes sense for a timer to bookmark this to use global Tk
> state commands.
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....
More information about the Python-list