[Tkinter-discuss] Adding something in Tkinter to facilitate package loading

Guilherme Polo ggpolo at gmail.com
Mon Feb 2 20:19:31 CET 2009


On Mon, Feb 2, 2009 at 2:21 AM, Guilherme Polo <ggpolo at gmail.com> wrote:
> Hi there,
>
> I was considering the possibility of adding something to facilitate
> package loading in Tkinter. If you have done a wrapper, or used one,
> you may have noticed that there is always some code like this:
>
>        global _TKTABLE_LOADED
>        if not _TKTABLE_LOADED:
>            tktable_lib = os.environ.get('TKTABLE_LIBRARY')
>            if tktable_lib:
>                master.tk.eval('global auto_path; '
>                                'lappend auto_path {%s}' % tktable_lib)
>            master.tk.call('package', 'require', 'Tktable')
>            _TKTABLE_LOADED = True
>
> This one was taken from the tktable wrapper (as you can see), some
> details will change from wrapper to wrapper (but apparently not by
> much).
>
> There is also the possibility that the wrapper modifies Tkinter.Tk
> (see ttk), or subclass it (see Tix), to inject this kind of code --
> which may be problematic. I see it as problematic when you want to
> test, lets say, a module P that depends on X and modifies Tkinter.Tk,
> and another module Q that depends on Y (but no X). When P is executed
> it does whatever it needs to load X, if loading X succeeds then it is
> all good, but lets suppose it failed. Now Q executes and tries
> instantiating Tkinter.Tk, the problem is that it doesn't depend on X
> to execute but P already modified it to load X (but it failed), now Q
> fails too. Maybe I'm just bringing this up because I decided to modify
> Tkinter.Tk on ttk, expected some form of problems initially, but
> started having real problems just now.
>
> Anyway, even if the second reason looks bad, I still would like to
> have something to load packages easily.

That first attempt went too fast from my part, I would say.

I've re-though about it today and came up with this:
http://tkinter.unpythonic.net/wiki/DependenceLoader

dependences.load_now would be called right before Tkinter.Tk.__init__finishes.

To add a tile dependence now I could do:
dependences.add('tile', basic_preloader, env_var='TILE_LIBRARY')

Which would be loaded when the Tcl intrerpreter is created. Hopefully
someone would like something like this too, and if possible check if
it would solve the problem for you too or if I'm thinking too much
about myself -- and only myself.

-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list