Script different! Mein Icon


 Python bei O'Reilly
 Python & Tkinter
 Tkinter (deutsch)
 Tkinter (english)
 ftp mit Python
 Warum Python?
 Erste Schritte
 Grafische Ausgabe
 Das Modul W
 Easy Dialogs
 Mac File Dialogs
 Piddle & MacOS X
 Dancing Python
 Blogger API
 Python & XML
 Python Cookbook

Python Logo

How To: MacPython and Tkinter (english)

Programming graphical user interfaces (GUI's) with the Tk-toolkit and MacPython is easy and fun. But unfortunately if you try the simplest demo script with a freshly installed MacPython you will get the following error messages:

Traceback (innermost last):
  File "MacHD:Python", line 1, in ?
    from Tkinter import *
  File "MacHD:Python", line 8, in ?
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

This is caused by a bug in the MacPython1.5.2c1 installer: it puts the shared libs »_tkinter.CFM68K.slb« and »_tkinter.ppc.slb« into the folder »PIL« which is in the folder »Imaging« in the folder »Extensions«. You have to put one (or both "Sidesmiley") of these files in the folder »PlugIns« which is in the folder »Mac«. In addition, the standard installation has no path to »$(PYTHON):Lib:lib-tk«. You must add this path manually using the program »EditPythonPrefs«.

You must run Tkinter based scripts using the interpreter (PythonInterpreter) rather than the IDE (Python IDE). This is documented. "Sidesmiley" Unfortunately there are two bugs in the interpreter to watch out for:

  • Calling »Tkinter« interactivetely from the interpreter causes a freeze. You can only run Tk-based Python scripts by saving them as text files and dropping them onto the interpreter, or by saving them as Python files and double clicking them to run them.

  • The preference "Enter interactive mode after script" is not compatible with Tk. If this preference is turned on then Tk scripts will not exit properly. To configure this setting drop PythonInterpreter onto EditPythonPrefs and push the "Default startup options..." button.

Thanks to Russell E. Owen for his help by the english version.

Mein Icon © Copyright 2000 - 2002: Jörg Kantel.
Last update: 13.10.2002; 21:33:49 Uhr.
This site is edited with Radio UserLand, the first personal Web Application server for Windows and Macintosh.  Let iCab smile  Site Meter