[Tkinter-discuss] Using 3rd party Tk/Tcl libraries with Python/Tkinter

Michael Lange klappnase at web.de
Mon Dec 20 19:11:22 CET 2010


Hi,

Thus spoketh python at bdurham.com 
unto us on Mon, 20 Dec 2010 12:18:00 -0500:

> >From time to time I've seen Tkinter developers reference 3rd party
> Tk/Tcl libraries. Some examples are the PMW widgets, TkDnd, and TkTable.

Pmw was added mistakenly to this list, it is 100% pure Python :)

> 
> Here are some questions about these 3rd party components from the
> perspective of a Python developer new to Tkinter (without any Tk/Tcl
> experience):
> 
> 1. Do these 3rd party components require compilation via a C compiler or
> is there a repository with pre-compiled components for each platform?

Depends, some extensions are pure tcl and thus can be used on any
platform without compiling, e.g. the tablelist widget:

http://www.nemethi.de/tablelist/tablelist.html

For extensions written in C, in most cases you will find a windows
binary file or installer on the project's web pages and a source code
distribution for unix. However on most unix systems binaries of one or
the other tk extensions are already included.

> 
> 2. Are there issues related to what version of Python a developer is
> using, eg. each release of Python uses a different version of Tk/Tcl?

Most Tk extensions I have seen work fine with tk-8.4 - 8.6 , but again,
your mileage may vary. For example , I couldn't get tkdnd to work on
debian lenny, which however seems to be a problem with something else on
my debian system, not Tk. If you want to install a precompiled windows
binary you will have to pick the one that matches your Tk version of
course.

> 
> 3. Where do these component's library files get placed on Windows,
> Linux, and Mac OS's?

On windows the folder containing the library files must be copied into
python's tcl distribution, usually something like c:\Python26\tcl .
On unix systems the ./configure && make && make install process will
usually (if all goes well) find automagically where to install the
extension, depending on where tcl/tk is installed, usually this
is /usr/lib.

> 
> What I understand so far is that one must find or create Python wrapper
> code in order to use 3rd party Tk/Tcl libraries. After that I'm stuck ;)

Yes, in order to use these extensions from tcl, one has to call

    package require packagename

which is similar to python's "import packagename" statement. So the python
wrapper must call this "require" command and then implement the
additional tcl functionality the package provides, all through the
widget.tk.call () mechanism that allows to execute tcl commands from
python.

> 
> BTW: My personal interest is in solutions that work with Python 2.7 for
> Windows but I thought I'd ask this question in a way that all Python
> developers might benefit.

There is no principle difference in this between python-2.7 and earlier
versions, as long as the tk-version python uses is supported by the
extension. Of course the syntax of the wrapper module must be supported
by your python version either, but if you are using a current python,
this will hardly ever be a problem.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

If I can have honesty, it's easier to overlook mistakes.
		-- Kirk, "Space Seed", stardate 3141.9


More information about the Tkinter-discuss mailing list