python – tkinter程序用cx_Freeze编译,但程序不会启动
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – tkinter程序用cx_Freeze编译,但程序不会启动,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2378字,纯文字阅读大概需要4分钟。
内容图文
我正在尝试按照本教程创建可执行文件
https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter
经过一些调整后,我能够编译项目但是当我点击.exe时,鼠标加载动画会触发,但什么都没有加载.此问题先前已被提出,但从未得到解决.
Where to start looking in the code when your .exe doesn’t work after cx_freeze?
我的app文件
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
任何帮助将不胜感激,我甚至不知道从哪里开始.
解决方法:
尝试修改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(当前版本).在此版本中,包含的模块位于构建目录的子目录库中.如果您使用5.0.1或更早版本,请设置
include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]
代替.
另见Getting “ImportError: DLL load failed: The specified module could not be found” when using cx_Freeze even with tcl86t.dll and tk86t.dll added in和python tkinter exe built with cx_Freeze for windows won’t show GUI
编辑:
另一个问题是cx_Freeze有一个python 3.7的错误,但尚未纠正.见Cx_freeze crashing Python3.7.0.你可以找到一个你应该手动应用的bug修复的链接(根据OP解决了这个问题,请参阅注释).
内容总结
以上是互联网集市为您收集整理的python – tkinter程序用cx_Freeze编译,但程序不会启动全部内容,希望文章能够帮你解决python – tkinter程序用cx_Freeze编译,但程序不会启动所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。