Introduction
Tix, the Tk Interface eXtension, is a powerful set of user interface components that expands the capabilities of your Tcl/Tk and Python applications. This page describes building a "Hello World" Tix application with py2exe.
Tix Hello World
Here is a very simple Tix application. Save it as hello.py:
setup.py for hello.py
py2exe doesn't discover the use of the Tix DLL and Tcl files, so you must include them explicitly. The following setup.py builds a working EXE for the hello.py above:
1 import glob
2 import os
3 import sys
4 from distutils.core import setup
5 import py2exe
6
7 def files(folder):
8 for path in glob.glob(folder+'/*'):
9 if os.path.isfile(path):
10 yield path
11
12 data_files=[
13 ('.', glob.glob(sys.prefix+'/DLLs/tix81*.dll')),
14 ('tcl/tix8.1', files(sys.prefix+'/tcl/tix8.1')),
15 ('tcl/tix8.1/bitmaps', files(sys.prefix+'/tcl/tix8.1/bitmaps')),
16 ('tcl/tix8.1/pref', files(sys.prefix+'/tcl/tix8.1/pref')),
17 ]
18
19 setup(
20 script_args=['py2exe'],
21 windows=['hello.py'],
22 data_files=data_files,
23 )
Alternative setup.py for hello.py
Another more ellaborated setup.py, without hard-coded versions of libraries and working with the bundle_files option (dlls for tcl, tk and tix must stand in the exec dir):
1 from distutils.core import setup
2 import py2exe
3 from py2exe.build_exe import py2exe as BuildExe
4 import os,sys
5
6 def TixInfo():
7 import Tkinter
8 import _tkinter
9
10 tk=_tkinter.create()
11
12 tcl_version=_tkinter.TCL_VERSION
13 tk_version=_tkinter.TK_VERSION
14 tix_version=tk.call("package","version","Tix")
15
16 tcl_dir=tk.call("info","library")
17
18 del tk, _tkinter, Tkinter
19
20 return (tcl_version,tk_version,tix_version,tcl_dir)
21
22 class myPy2Exe(BuildExe):
23
24 def plat_finalize(self, modules, py_files, extensions, dlls):
25 BuildExe.plat_finalize(self, modules, py_files, extensions, dlls)
26
27 if "Tix" in modules:
28 # Tix adjustments
29 tcl_version,tk_version,tix_version,tcl_dir = TixInfo()
30
31 tixdll="tix%s%s.dll"% (tix_version.replace(".",""),
32 tcl_version.replace(".",""))
33 tcldll="tcl%s.dll"%tcl_version.replace(".","")
34 tkdll="tk%s.dll"%tk_version.replace(".","")
35
36 dlls.add(os.path.join(sys.prefix,"DLLs",tixdll))
37
38 self.dlls_in_exedir.extend( [tcldll,tkdll,tixdll ] )
39
40 tcl_src_dir = os.path.split(tcl_dir)[0]
41 tcl_dst_dir = os.path.join(self.lib_dir, "tcl")
42 self.announce("Copying TIX files from %s..." % tcl_src_dir)
43 self.copy_tree(os.path.join(tcl_src_dir, "tix%s" % tix_version),
44 os.path.join(tcl_dst_dir, "tix%s" % tix_version))
45
46 opts={
47 'py2exe':{
48 'bundle_files':1
49 }
50 }
51
52 setup(
53 script_args=['py2exe'],
54 cmdclass={'py2exe':myPy2Exe},
55 windows=['hello.py'],
56 options=opts,
57 )