3 # Delay import _tkinter until we have set TCL_LIBRARY,
4 # so that Tcl_FindExecutable has a chance to locate its
7 # Unfortunately, we cannot know the TCL_LIBRARY directory
8 # if we don't know the tcl version, which we cannot find out
9 # without import Tcl. Fortunately, Tcl will itself look in
10 # <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
11 # the real Tcl library will do.
13 # Expand symbolic links on Vista
16 ctypes
.windll
.kernel32
.GetFinalPathNameByHandleW
17 except (ImportError, AttributeError):
22 assert isinstance(s
, str) # sys.prefix contains only bytes
23 udir
= s
.decode("mbcs")
24 hdir
= ctypes
.windll
.kernel32
.\
25 CreateFileW(udir
, 0x80, # FILE_READ_ATTRIBUTES
27 None, 3, # OPEN_EXISTING
28 0x02000000, # FILE_FLAG_BACKUP_SEMANTICS
31 # Cannot open directory, give up
33 buf
= ctypes
.create_unicode_buffer(u
"", 32768)
34 res
= ctypes
.windll
.kernel32
.\
35 GetFinalPathNameByHandleW(hdir
, buf
, len(buf
),
37 ctypes
.windll
.kernel32
.CloseHandle(hdir
)
39 # Conversion failed (e.g. network location)
41 s
= buf
[:res
].encode("mbcs")
43 if s
.startswith("\\\\?\\"):
45 if s
.startswith("UNC"):
49 prefix
= os
.path
.join(sys
.prefix
,"tcl")
50 if not os
.path
.exists(prefix
):
52 prefix
= os
.path
.join(sys
.prefix
, os
.path
.pardir
, "tcltk", "lib")
53 prefix
= os
.path
.abspath(prefix
)
54 # if this does not exist, no further search is needed
55 if os
.path
.exists(prefix
):
56 prefix
= convert_path(prefix
)
57 if "TCL_LIBRARY" not in os
.environ
:
58 for name
in os
.listdir(prefix
):
59 if name
.startswith("tcl"):
60 tcldir
= os
.path
.join(prefix
,name
)
61 if os
.path
.isdir(tcldir
):
62 os
.environ
["TCL_LIBRARY"] = tcldir
63 # Compute TK_LIBRARY, knowing that it has the same version
66 ver
= str(_tkinter
.TCL_VERSION
)
67 if "TK_LIBRARY" not in os
.environ
:
68 v
= os
.path
.join(prefix
, 'tk'+ver
)
69 if os
.path
.exists(os
.path
.join(v
, "tclIndex")):
70 os
.environ
['TK_LIBRARY'] = v
71 # We don't know the Tix version, so we must search the entire
73 if "TIX_LIBRARY" not in os
.environ
:
74 for name
in os
.listdir(prefix
):
75 if name
.startswith("tix"):
76 tixdir
= os
.path
.join(prefix
,name
)
77 if os
.path
.isdir(tixdir
):
78 os
.environ
["TIX_LIBRARY"] = tixdir