Differences between revisions 21 and 22
Revision 21 as of 2004-10-26 18:31:58
Size: 5179
Comment: Add troubleshooting info
Revision 22 as of 2004-12-15 00:42:31
Size: 5169
Comment: Update URL for Tk site
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
 * [http://www.tcl-tk.net/man/ Online Tcl/Tk Manual Pages] - the official man pages at the Tcl Developer Xchange.  * [http://www.tcl.tk/man/ Online Tcl/Tk Manual Pages] - the official man pages at the Tcl Developer Xchange.
Line 33: Line 33:
        * [http://www.tcl-tk.net Tcl Developer Xchange]         * [http://www.tcl.tk Tcl Developer Xchange]
Line 89: Line 89:

Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/[http://wiki.tcl.tk/tk Tk].

Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one, and almost the only one that is portable between Unix, Mac and Windows. CameronLaird calls the yearly decision to keep TkInter "one of the minor traditions of the Python world."

The Tkinter wiki: http://tkinter.unpythonic.net/wiki/

Tkinter Documentation

David McNab recommended the latter two as particularly "pythonic" in not insisting that readers think in Tcl.

Tkinter Extensions

Comments

MythDebunking: TkInter is ugly on Windows (http://wiki.tcl.tk/TkWidgetsLookFine)

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 how to fix the problem, [news:comp.lang.python ask for help].

TkInter (last edited 2022-02-08 22:05:48 by martinmiller)

Unable to edit the page? See the FrontPage for instructions.