Tkinter Troubleshooting

Windows gotchas

Starting with Python 1.5.2 beta 1, the Tcl/Tk installer is included by in the Python installer, and (if you leave the checkbox checked) automatically run at the end of the Python installation.

On Windows 95 and 98, you have to edit autoexec.bat after installing Tcl/Tk to ensure that the TCL/TK DLLs can be found; see the download instructions for details.

If you had an older version of Tcl/Tk installed and have now upgraded to 8.0.4 or later, you may get an error message about the <MouseWheel> event. This means that the old (8.0.3 or older) Tcl/Tk DLLs are used with the new Tcl/Tk scripts. Track down the old DLLs and throw them away, or copy the new ones (from C:\Program Files\Tcl\bin) on top of them.

Don't use Tcl/Tk versions before 8.0, they are flakey.

Tkinter currently doesn't work under PythonWin (Mark Hammond's interactive Python development environment). It does work with the MS-DOS console version (python.exe) and with the console-free version (pythonw.exe).

The systematic checking procedure given below is also helpful.

(You may still find Michael Ryan's web page Installing Python/Tkinter on Windows 95 useful, even though it is geared towards Python 1.4, when the process was much less smooth.)

Macintosh gotchas

The Mac installation is pretty smooth, as long as you have recent system software and enough memory, and it automatically installs Tcl/Tk for you, so you don't have to do anything.

Don't use older Tcl/Tk versions than 8.0, they are flakey.

The systematic checking procedure given below is also helpful.

Unix gotchas

On Unix, a number of common problems occur.

A common configuration problem is to have header files tcl.h or tk.h installed (often in /usr/local/include) that don't match the library files, libtcl<version>.a and libtk<version>.a (or similar names ending in .so), often in /usr/local/lib. This often results in unsatisfied references at link time or even at import time (when Tcl/Tk themselves are shared libraries). Locate the files and compare the version numbers in tcl.h/tk.h (search for TCL_VERSION and TK_VERSION) to the library version numbers. Also note that before Tcl/Tk 8.0, "matching" Tcl/Tk versions were 7.5/4.1 and 7.6/4.2.

Use the systematic checking procedure below to check your installation.

Checking your Tkinter support

A good way to systematically check whether your Tkinter support is working is the following.

Enter an interactive Python interpreter in a shell on an X console.

Step 1 - can _tkinter be imported?

Try the following command at the Python prompt:

>>> import _tkinter # with underscore, and lowercase 't'
  • If it works, skip to the next step.

  • If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Edit Modules/Setup (read the instructions at the top, search for _tkinter, read more instructions there, and follow the instructions) and rebuild and reinstall. Make sure to enable the _tkinter module as well as the TKPATH variable definition.

  • If it fails with an error from the dynamic linker, see above (for Unix, check for a header/library file mismatch; for Windows, check that the TCL/TK DLLs can be found).

Step 2 - can Tkinter be imported?

Try the following command at the Python prompt:

>>> import Tkinter # no underscore, uppercase 'T'
  • If it works, skip to the next step.

  • If it fails with "No module named Tkinter", your Python configuration need to be changed to include the directory that contains Tkinter.py in its default module search path. You have probably forgotten to define TKPATH in the Modules/Setup file. A temporary workaround would be to find that directory and add it to your PYTHONPATH environment variable. It is the subdirectory named "lib-tk" of the Python library directory (when using Python 1.4 or before, it is named "tkinter").

Step 3 - does Tkinter work?

Try the following command at the Python prompt:

>>> Tkinter._test() # note underscore in _test()
  • This should pop up a small window with two buttons. Clicking the "Quit" button makes it go away and the command return. If this works, you're all set. (When running this test on Windows, from Python run in a MS-DOS console, the new window somehow often pops up *under* the console window. Move it aside or locate the Tk window in the Taskbar.)

  • If this doesn't work, study the error message you get; if you can't see to fix the problem, call your customer service representative.