Re: help with tkinter installation please

Guido.van.Rossum@cwi.nl
Mon, 02 Jan 1995 13:34:22 +0100

Steve Morris writes:

> I`m trying to do anything with tkinter and would appreciate some step
> by step instructions. So far I have done the following:
>
> 1) Installed Tcl/Tk and tested with various Tk demo routines. I installed
> this on my sparc out of the box, i.e. standard configuration.
>
> 2) I installed python-1.1 out of the box, standard configuration,
> including libraries and man pages.
>
> 3) I then edited Modules/Setup as follows:
>
> # Steen Lumholt's tkinter module. For use with plain Tk, use the
> # first line. For use with extended Tk, edit tkappinit.c, add
> # appropriate -DWITH_... and libraries/objects to the second line, and
> # use that. In all cases also enable the last line (TKPATH).
>
> # *** Use ONE of the following two lines, see previous comments ***
> tkinter tkintermodule.c -I/usr/local/include -L/usr/local/lib -ltk -ltcl -lX11
> #tkinter tkintermodule.c tkappinit.c -DWITH_APPINIT -I/usr/local/include -L/usr/local/lib -ltk -ltcl -lX11
>
> TKPATH=:$(DESTLIB)/tkinter
>
> 4) Made and installed same.

Looks good so far. To make sure that the "tkinter" module has been
incorporated into the python binary, run it and type "import tkinter"
-- this should give another prompt without an error.

> 5) In Demos/tkinter/guido I try to run dialog.py as follows:
>
> yar% python dialog.py
> Traceback (innermost last):
> File "dialog.py", line 7, in ?
> from Tkinter import *
> ImportError: No module named Tkinter
> yar%

To which Olivier Marce replies:

> Just rename tkinter module in Tkinter.

No, NO, NOOO!

The Tkinter (capital T) module is a *different* module than tkinter
with lower case t!). Tkinter (capital T) is written in Python and
lives in Lib/tkinter/Tkinter.py. The effect of enabling the line
"TKPATH=:$(DESTLIB)/tkinter" in the Setup file is to add the directory
Lib/tkinter (really $(DESTLIB)/tkinter) to Python's default module
search path. To check that this has indeed happened, run python and
type

import sys
print sys.path

This should give a list of directory names including one that ends in
tkinter. If it doesn't, your installation hasn't been completed (or
you are using the wrong Python binary). If it does, maybe that
directory doesn't exist, or the Tkinter.py file wasn't installed
there.

To fix it temporarily, you can set the PYTHONPATH environment variable
to point to the right directory (e.g. Lib/tkinter in the source tree).

Steve continues:

> PS. I would also appreciate knowing where in the documentation this is
> discussed. I tried the following in the python directory with no joy:
>
> find . -exec grep -i tkinter {} /dev/null \;
>
> It does seem to me that newbie documentation telling how to run demo's
> should be a little easier to find.

Well there's no limit to the number of ways newbies can botch the
installation so it's no use trying to cope with all possibilities.
What you did should have worked. The Tkinter documentation is
available on the ftp site ftp.cwi.nl in pub/python as
tkinter-doc.tar.gz (this is a compressed tar archive containing a
PostScript file).

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>