使用Pyinstaller问题创建Python Tkinter exe文件

时间:2019-02-25 05:28:16

标签: python tkinter pyinstaller

我已经成功地用Tkinter创建了GUI python2.7程序,没有错误。现在,我想在anaconda环境中使用pyinstaller制作可执行文件(我正在使用Windows 10)。

使用此命令 pyinstaller --onefile main.py我能够在dist文件夹中成功创建exe文件。但是,当我尝试运行exe文件时,它显示错误:

Traceback (most recent call last):   
File "main.py", line 333, in <module>   
File "main.py", line 90, in __init__   
File "lib-tk\ttk.py", line 715, in current
_tkinter.TclError: Index 0 out of range 
[22668] Failed to execute script main

问题与tkinter有关吗?我在这里Problems with Pyinstaller with tkinter app on python 3.5和这里:How to make pyinstaller import the ttk theme?都尝试过该解决方案。但是还是一样的错误

1 个答案:

答案 0 :(得分:0)

尝试做:

pyinstaller --onefile -w main.py

-w标志阻止python启动控制台,因此这可能就是tkinter失败的原因。

来源: This cool video

我强烈建议您观看此视频,因为它也深入探讨了在构建exe后如何清理的情况。