diff options
author | Guido van Rossum <guido@python.org> | 1999-01-04 18:06:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-04 18:06:45 (GMT) |
commit | f8d579c5e3b9938599c1ae0a6a8a73b70ea1e5da (patch) | |
tree | 5bc377d67b337c8c7a7c4fdb8b500104d6e04da2 | |
parent | 88303194a5579647b30243ab85f3f3acfd610d3c (diff) | |
download | cpython-f8d579c5e3b9938599c1ae0a6a8a73b70ea1e5da.zip cpython-f8d579c5e3b9938599c1ae0a6a8a73b70ea1e5da.tar.gz cpython-f8d579c5e3b9938599c1ae0a6a8a73b70ea1e5da.tar.bz2 |
This hopefully fixes the problem of having to set PATH
in autoexec.bat in order to find the Tcl DLLs -- Tkinter calls FixTk
which will hunt around in a few common places and then set PATH
and try again, or else issue a big clarifying error message.
-rw-r--r-- | Lib/lib-tk/FixTk.py | 64 | ||||
-rw-r--r-- | Lib/lib-tk/Tkinter.py | 5 |
2 files changed, 68 insertions, 1 deletions
diff --git a/Lib/lib-tk/FixTk.py b/Lib/lib-tk/FixTk.py new file mode 100644 index 0000000..6c7de03 --- /dev/null +++ b/Lib/lib-tk/FixTk.py @@ -0,0 +1,64 @@ +"""Utility which tries to locate the Tcl/Tk 8.0 DLLs on Windows. + +This is a no-op on other platforms. +""" + +# Error messages we may spit out + +NO_TCL_MESSAGE = """\ +WHOOPS! I can't find a Tcl/Tk 8.0 installation anywhere. +Please make sure that Tcl.Tk 8.0 is installed and that the PATH +environment variable is set to include the Tcl/bin directory +(or wherever TK80.DLL and TCL80.DLL are installed). +If you don't know how to fix this, consider searching the Python FAQ +for the error you get; post to the comp.lang.python if all else fails. +Read the source file FixTk.py for details. +""" + +NO_TKINTER_MESSAGE = """\ +WHOOPS! Even though I think I have found a Tcl/Tk 8.0 installation, +I can't seem to import the _tkinter extension module. +I get the following exception: + ImportError: %s +If you don't know how to fix this, consider searching the Python FAQ +for the error you get; post to the comp.lang.python if all else fails. +Read the source file FixTk.py for details. +""" + +import sys +if sys.platform == "win32": + try: + import _tkinter + except ImportError: + import os + try: + path = os.environ['PATH'] + except KeyError: + path = "" + python_exe = sys.executable + python_dir = os.path.dirname(python_exe) + program_files = os.path.dirname(python_dir) + def tclcheck(dir): + for dll in "tcl80.dll", "tk80.dll", "tclpip80.dll": + if not os.path.isfile(os.path.join(dir, dll)): + return 0 + return 1 + for tcldir in [program_files, "\\Program files", "\\", + "C:\\Program Files", "D:\\Program Files"]: + tcldir = os.path.join(tcldir, "Tcl", "bin") + if tclcheck(tcldir): + break + else: + tcldir = None + if not tcldir: + sys.stderr.write(NO_TCL_MESSAGE) + else: + if path and path[-1] != os.pathsep: + path = path + os.pathsep + path = path + tcldir + os.environ["PATH"] = path + os.putenv("PATH", path) + try: + import _tkinter + except ImportError, message: + sys.stderr.write(NO_TKINTER_MESSAGE % str(message)) diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index 04a863a..344dd8a 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -2,7 +2,10 @@ __version__ = "$Revision$" -import _tkinter # If this fails your Python is not configured for Tk +import sys +if sys.platform == "win32": + import FixTk # Attempt to configure Tcl/Tk without requiring PATH +import _tkinter # If this fails your Python may not be configured for Tk tkinter = _tkinter # b/w compat for export TclError = _tkinter.TclError from types import * |