FixTk.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import sys, os
  2. # Delay import _tkinter until we have set TCL_LIBRARY,
  3. # so that Tcl_FindExecutable has a chance to locate its
  4. # encoding directory.
  5. # Unfortunately, we cannot know the TCL_LIBRARY directory
  6. # if we don't know the tcl version, which we cannot find out
  7. # without import Tcl. Fortunately, Tcl will itself look in
  8. # <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
  9. # the real Tcl library will do.
  10. prefix = os.path.join(sys.prefix,"tcl")
  11. # if this does not exist, no further search is needed
  12. if os.path.exists(prefix):
  13. if not os.environ.has_key("TCL_LIBRARY"):
  14. for name in os.listdir(prefix):
  15. if name.startswith("tcl"):
  16. tcldir = os.path.join(prefix,name)
  17. if os.path.isdir(tcldir):
  18. os.environ["TCL_LIBRARY"] = tcldir
  19. # Compute TK_LIBRARY, knowing that it has the same version
  20. # as Tcl
  21. import _tkinter
  22. ver = str(_tkinter.TCL_VERSION)
  23. if not os.environ.has_key("TK_LIBRARY"):
  24. v = os.path.join(prefix, 'tk'+ver)
  25. if os.path.exists(os.path.join(v, "tclIndex")):
  26. os.environ['TK_LIBRARY'] = v
  27. # We don't know the Tix version, so we must search the entire
  28. # directory
  29. if not os.environ.has_key("TIX_LIBRARY"):
  30. for name in os.listdir(prefix):
  31. if name.startswith("tix"):
  32. tixdir = os.path.join(prefix,name)
  33. if os.path.isdir(tixdir):
  34. os.environ["TIX_LIBRARY"] = tixdir