【问题标题】:Creating Python Tkinter exe file with Pyinstaller problem使用 Pyinstaller 问题创建 Python Tkinter exe 文件
【发布时间】:2019-07-18 11:45:52
【问题描述】:

我用 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?。但还是一样的错误

【问题讨论】:

  • 我会使用 cx_freeze 来编译一个 exe。我用那个库而不是 pyinstaller 做了一些项目。
  • 为此使用 Py-Auto-Gui

标签: python tkinter pyinstaller


【解决方案1】:

试一试:

pyinstaller --onefile -w main.py

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

来源: This cool video

我强烈建议您观看此视频,因为它还深入介绍了如何在构建 exe 后进行清理。

【讨论】:

  • 刚刚意识到这是一年前发布的。
猜你喜欢
  • 1970-01-01
  • 2020-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-14
  • 2019-11-18
  • 2019-09-15
  • 2022-11-20
相关资源
最近更新 更多