blob: 6c7de03efa2e3924d2836e72d11d3335f9c20776 [file] [log] [blame]
Guido van Rossumf8d579c1999-01-04 18:06:45 +00001"""Utility which tries to locate the Tcl/Tk 8.0 DLLs on Windows.
2
3This is a no-op on other platforms.
4"""
5
6# Error messages we may spit out
7
8NO_TCL_MESSAGE = """\
9WHOOPS! I can't find a Tcl/Tk 8.0 installation anywhere.
10Please make sure that Tcl.Tk 8.0 is installed and that the PATH
11environment variable is set to include the Tcl/bin directory
12(or wherever TK80.DLL and TCL80.DLL are installed).
13If you don't know how to fix this, consider searching the Python FAQ
14for the error you get; post to the comp.lang.python if all else fails.
15Read the source file FixTk.py for details.
16"""
17
18NO_TKINTER_MESSAGE = """\
19WHOOPS! Even though I think I have found a Tcl/Tk 8.0 installation,
20I can't seem to import the _tkinter extension module.
21I get the following exception:
22 ImportError: %s
23If you don't know how to fix this, consider searching the Python FAQ
24for the error you get; post to the comp.lang.python if all else fails.
25Read the source file FixTk.py for details.
26"""
27
28import sys
29if sys.platform == "win32":
30 try:
31 import _tkinter
32 except ImportError:
33 import os
34 try:
35 path = os.environ['PATH']
36 except KeyError:
37 path = ""
38 python_exe = sys.executable
39 python_dir = os.path.dirname(python_exe)
40 program_files = os.path.dirname(python_dir)
41 def tclcheck(dir):
42 for dll in "tcl80.dll", "tk80.dll", "tclpip80.dll":
43 if not os.path.isfile(os.path.join(dir, dll)):
44 return 0
45 return 1
46 for tcldir in [program_files, "\\Program files", "\\",
47 "C:\\Program Files", "D:\\Program Files"]:
48 tcldir = os.path.join(tcldir, "Tcl", "bin")
49 if tclcheck(tcldir):
50 break
51 else:
52 tcldir = None
53 if not tcldir:
54 sys.stderr.write(NO_TCL_MESSAGE)
55 else:
56 if path and path[-1] != os.pathsep:
57 path = path + os.pathsep
58 path = path + tcldir
59 os.environ["PATH"] = path
60 os.putenv("PATH", path)
61 try:
62 import _tkinter
63 except ImportError, message:
64 sys.stderr.write(NO_TKINTER_MESSAGE % str(message))