一尘不染

tkinter程序使用cx_Freeze编译,但程序无法启动

python

我正在尝试按照本教程创建可执行文件

https://github.com/anthony-
tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter

进行一些调整后,我可以编译项目,但是当我单击.exe时,会触发加载鼠标的动画,但没有任何加载。之前曾问过这个问题,但从未解决过。

我的应用程式档案

from tkinter import *
from tkinter import messagebox

root = Tk()
root.title('Button')
print("something")
new = messagebox.showinfo("Title", "A tk messagebox")
root.mainloop()

我的setup.py

import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [
    Executable('SimpleTkApp.py', base=base)
]

setup(name='simple_Tkinter',
      version='0.1',
      description='Sample cx_Freeze Tkinter script',
      executables= [Executable("SimpleTkApp.py", base=base)])

另外我一直在手动添加TCL / TK库

set TK_LIBRARY=C:\...\tk8.6  etc

我的配置:python 3.7,cx_Freeze 5.1.1

任何帮助将不胜感激,我什至不知道从哪里开始。


阅读 165

收藏
2020-12-20

共1个答案

一尘不染

尝试setup.py如下修改您:

import sys
from cx_Freeze import setup, Executable

import os
PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

include_files = [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
                 (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll'))]

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [Executable('SimpleTkApp.py', base=base)]

setup(name='simple_Tkinter',
      version='0.1',
      description='Sample cx_Freeze Tkinter script',
      options={'build_exe': {'include_files': include_files}},
      executables=executables)

这应该适用于cx_Freeze版本5.1.1(当前版本)。在此版本中,包含的模块位于lib构建目录的子目录中。如果使用5.0.1或更早版本,请设置

include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                 os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]
2020-12-20