Pythonmania

Script Different!

Suchen in:
Suche:
In Partnerschaft mit Amazon.de
Startseite | Schockwellenreiter | Impressum
Anzeigen


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
1.5.2c1:Demo:tkinter:matt:animation-w-velocity-ctrl.py",
line 1, in ?
    from Tkinter import *
  File "MacHD:Python 1.5.2c1:Lib:lib-tk:Tkinter.py",
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.






Werbung: