| tk85%and%python |
UserPreferences |
| Tkinter Wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
So you are one of those using Tkinter to develop GUI applications. But you do not appreciate its looking anymore, or, even, some widgets that could be considered fundamental by some are not there either (e.g.: Notebook and Treeview). This is past, the future is here, Tk 8.5 has landed! Right, this news is not that new for some, but for most people it is. Before Tk 8.5 there was Tile, which brought new widgets and themes, but people using X11 still had to live with that ugly font rendering. Tk 8.5 then gave us anti-aliased text under X11, and other additional features like Window transparency, smooth scrolling for text widget and the possibility to pass an arbritrary Tk object in virtual events. For several other toolkits, all these "new features" are not new at all but at least Tk has evolved and you can start using these features now.
Tkinter is what makes it possible to use Tk under Python. It doesn't support Tk versions older than 8.2 (note that Tk 8.2.3 was released 9 years ago), but it doesn't impose any restrictions to disallow compilation against Tk 8.5 or even 8.6a. This ends up working mainly because Tk is highly compatible between versions. But, just because it compiles against Tk 8.5, this doesn't mean you can go and use its features without pain, for this you will need a Ttk (the name given for all the new widgets and theming support) wrapper.
Since Python itself doesn't provide a Ttk wrapper, you will have to get one. The one I'm going to recommended supports all current Ttk features and can be downloaded from PyPI at http://pypi.python.org/pypi/pyttk, it works under Python 2.5, Python 2.6b and Python 3.0b, also, it supports new tile versions, Tk 8.5 up to Tk 8.5.3 features and some of the new features that Tk 8.6 is bringing, besides this there is a possibility of it being included in the Python (2.7/3.1) release (http://bugs.python.org/issue2983).
The Windows installer for
Python 2.6b2 already includes Tk 8.5.3 so all you have to do is install it and the Ttk wrapper if you want to use Tk 8.5 features (why wouldn't you want to?).
But maybe you don't want to use Python 2.6b yet, or maybe you can't, or something else. This leaves you with four options. The first option is to not use Tk 8.5 (but then you wouldn't be reading this, I guess), the second one is to recompile Python with Tcl/Tk 8.5, the third one uses Tile only and the last one involves finding someone that distributes Python 2.5 binary packages where Tkinter was compiled against Tcl/Tk 8.5.
If you pick the second option, there isn't much more I can say.
In case you pick the third option I'm supposing you don't want to compile Tile, so you can go and download the .zip (following links at http://tktable.sourceforge.net/tile/) which just requires you to unpack the file. After this all you have to do is adjust the TILE_LIBRARY environment variable, it should point to the place where tile was unpacked. After this is done you are ready to start using the ttk features.
And now there is the last option, for which I bring bad news. I'm not aware of any binary distribution of Python 2.5 that is compiled against Tk 8.5.
You should know that Python.org doesn't provide binary packages for Linux, so it is not as easy as it is under Windows to start using these new features. But hopefully your Linux distribution, at some point, should start distributing Python packages, in whatever format it uses, where Tkinter is compiled against Tcl/Tk 8.5. But chances are you don't want to wait for this to happen, and fortunately there are other options you can resort to. The first, and possibly better, option is to compile Python yourself. This option also extends to other platforms, and it is relatively easy to do it. If possible, stick to this one for now.
Another option is to use just Tile, and it is possible that your distro already has a package for it (in Ubuntu it is called tk-tile). After installing it, you are ready to use the ttk features. The drawback of using Tile under Linux is that you don't get the nice anti-aliased fonts (and the other Tk 8.5 features, of course).
Still under the "Tile option", it may be possible that your distro has no binary package for it. Just like you would do for other things, you will need to grab its source (http://tktable.sourceforge.net/tile/), compile and install. After installing it, it is possible that Tk will not be able to just find where it was installed and in that case you should set the TILE_LIBRARY environment variable to point to where you installed tile before trying to use the Ttk wrapper.
This section is targetted to people using Python 2.5.2, and earlier, with Tk 8.5. Python 2.6b already includes what I'm going to list here, and a future Python 2.5.3 will have this fixed too.
Till Tk 8.4 there were no widgets with options that supported a list or tuple as its value, so Tkinter didn't need to support it, but the problem is that there are widgets with such options now. As a consequence, passing a list or a tuple to an option that supports it causes Python 2.5.2, and earlier, to segfault. The fix for this can be found at http://bugs.python.org/issue2906 (both patches need to be applied), and it doesn't involve recompilation, the patches just change Tkinter.py.
As I remember, and could find so far, the above problem is the only critical one that you may hit.