Skip to content

Instantly share code, notes, and snippets.

@pmdevita
Created December 16, 2017 17:16
Show Gist options
  • Save pmdevita/e037d48471590ab8d65eab3a054d8101 to your computer and use it in GitHub Desktop.
Save pmdevita/e037d48471590ab8d65eab3a054d8101 to your computer and use it in GitHub Desktop.
cx_Freeze a python tkinter app
import sys, os
from cx_Freeze import setup, Executable
project_name = "My Tkinter App"
exe_name = "MyTkinterApp"
version = "1"
main_script = "main.py"
optimization = 0
resources = []
packages = ["tkinter"]
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [Executable("main.py", base=base, targetName=exe_name+".exe")]
os.environ['TCL_LIBRARY'] = sys.exec_prefix + "\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = sys.exec_prefix + "\\tcl\\tk8.6"
resources.extend([sys.exec_prefix + "\\DLLs\\tcl86t.dll", sys.exec_prefix + "\\DLLs\\tk86t.dll"])
elif sys.platform == "darwin":
executables = [Executable("main.py", base=base)]
build_exe_options = {"optimize": optimization, "include_files": resources, "packages": packages}
mac_options = {"bundle_name": exe_name}
setup( name = project_name,
version = version,
options = {"build_exe": build_exe_options},
bdist_mac = mac_options,
executables = [Executable(main_script, base=base, targetName=exe_name+".exe")]
)
@pmdevita
Copy link
Author

pmdevita commented Dec 16, 2017

On Windows, Tkinter doesn't automatically throw in the tcl and dll files needed. This adds the files in during the building process
On Mac, make sure you have ActiveTCL installed (go here and download the .dmg for the 8.5 release). Mac currently seems to be broken with cx_freeze and tkinter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment