[Tutor] about Tix

Alan Gauld alan.gauld at btinternet.com
Fri Oct 26 10:07:07 CEST 2007


Linda,

>I run the following code in Python 2.5 and got the error (when I do
> "import Tix", no error).

Congratulations I think this might just be the first Tix question
on the tutor list! :-)

> Traceback (most recent call last):
>  File "2.py", line 54, in <module>
>    tkRoot = Tix.Tk( )
>  File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tix.py",
> line 210, in __init__
>    self.tk.eval('package require Tix')
> _tkinter.TclError: can't find package Tix

This looks to me like the Tix DLL hasn't been installed or it's
installed in a folder where it can''t be found. The Tix module
is just a wrapper round the Tix DLL so you need both.

It works OK for me:

>>> import Tix as t
>>> tk = t.Tk()
>>> w = t.Toplevel(tk)
>>> b = t.Label(w, text="Hello")
>>> b.pack()
>>> t.mainloop()

However,

> from __future__ import with_statement   # <-- Python 2.5 ONLY
> import Tix
> import time
>
> class SplashScreen( object ):
...
> #--------------------------------------------
> # Now putting up splash screens is simple
>
> # Create the tkRoot window
> tkRoot = Tix.Tk( )
>
> with SplashScreen( tkRoot, 'splashImage.jpg', 3.0 ):

I'm not sure you need the with statement here.
(Although this might also be the first tutor example of a
custom context manager! Two firsts in one mail...:)

Couldn't you just call the SplashScreen directly?
Then initialise and build the GUI? Its what I usually
do and it seems to work. I'm trying to work out what
advantage the with gives?

>   initializeMyApplication( )
>   buildTheGUI( tkRoot )
>
> tkRoot.mainloop( )

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list