Skip to content

Commit 0c1add8

Browse files
committed
Add work-a-round for tkinter usage with virtualenv under windows, see:
pypa/virtualenv#93
1 parent a35a94c commit 0c1add8

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

README.creole

+3
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ Six is a Python 2 and 3 compatibility library.
412412
413413
== History
414414

415+
* [[https://github.com/jedie/DragonPy/compare/v0.5.0...v0.5.1|??.08.2015 - v0.5.1]]: (not released, yet)
416+
** Add a "starter GUI"
417+
** Add work-a-round for tkinter usage with virtualenv under windows, see: [[https://github.com/pypa/virtualenv/issues/93|virtualenv issues #93]]
415418
* [[https://github.com/jedie/DragonPy/compare/v0.4.0...v0.5.0|18.08.2015 - v0.5.0]]:
416419
** ROM files will be downloaded on-the-fly ({{{.sh}}} scripts are removed. So it's easier to use under Windows)
417420
* [[https://github.com/jedie/DragonPy/compare/v0.3.2...v0.4.0|26.05.2015 - v0.4.0]]:

dragonpy/__init__.py

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
1+
import os
2+
import sys
13

2-
__version__ = "0.5.0"
4+
5+
__version__ = "0.5.1.dev0"
6+
7+
8+
def fix_virtualenv_tkinter():
9+
"""
10+
work-a-round for tkinter under windows in a virtualenv:
11+
"TclError: Can't find a usable init.tcl..."
12+
Known bug, see: https://github.com/pypa/virtualenv/issues/93
13+
14+
There are "fix tk" file here:
15+
16+
C:\Python27\Lib\lib-tk\FixTk.py
17+
C:\Python34\Lib\tkinter\_fix.py
18+
19+
These modules will be automatic imported by tkinter import.
20+
21+
The fix set theses environment variables:
22+
23+
TCL_LIBRARY C:\Python27\tcl\tcl8.5
24+
TIX_LIBRARY C:\Python27\tcl\tix8.4.3
25+
TK_LIBRARY C:\Python27\tcl\tk8.5
26+
27+
TCL_LIBRARY C:\Python34\tcl\tcl8.6
28+
TIX_LIBRARY C:\Python34\tcl\tix8.4.3
29+
TK_LIBRARY C:\Python34\tcl\tk8.6
30+
31+
but only if:
32+
33+
os.path.exists(os.path.join(sys.prefix,"tcl"))
34+
35+
And the virtualenv activate script will change the sys.prefix
36+
to the current env. So we temporary change it back to sys.real_prefix
37+
and import the fix module.
38+
If the fix module was imported before, then we reload it.
39+
"""
40+
if "TCL_LIBRARY" in os.environ:
41+
# Fix not needed (e.g. virtualenv issues #93 fixed?)
42+
return
43+
44+
if not hasattr(sys, "real_prefix"):
45+
# we are not in a activated virtualenv
46+
return
47+
48+
if sys.version_info[0] == 2:
49+
# Python v2
50+
virtualprefix = sys.prefix
51+
sys.prefix = sys.real_prefix
52+
53+
import FixTk
54+
55+
if "TCL_LIBRARY" not in os.environ:
56+
reload(FixTk)
57+
58+
sys.prefix = virtualprefix
59+
else:
60+
# Python v3
61+
virtualprefix = sys.base_prefix
62+
sys.base_prefix = sys.real_prefix
63+
64+
from tkinter import _fix
65+
66+
if "TCL_LIBRARY" not in os.environ:
67+
from imp import reload
68+
reload(_fix)
69+
70+
sys.base_prefix = virtualprefix
71+
72+
73+
if sys.platform.startswith("win"):
74+
fix_virtualenv_tkinter()

0 commit comments

Comments
 (0)