使用cx_freeze为tkinter接口创建.exe文件

时间:2014-02-25 04:37:21

标签: python tkinter cx-freeze

我在这个地方找到了这个答案,但我找不到答案。我有一个python脚本(3.3),它有一个与tkinter的接口。我用cx_freeze从中创建了一个可执行文件,得到了一个包含一些文件和文件夹的build文件夹。我双击.exe文件,没有任何反应。我正在使用以下设置:

import sys

from cx_Freeze import setup, Executable



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

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

如果我只是打开我的代码并运行它,界面就可以完美运行。在构建时我没有得到任何错误消息(至少没有我能看到的......顺便说一句,我如何验证这个?)。关于问题可能是什么的任何想法?或任何其他替代模块?

谢谢! :)

1 个答案:

答案 0 :(得分:5)

我会发表评论,但我还没有声誉......

编译输出/日志中的任何警告/错误?

在命令提示符下运行可执行文件时的任何内容?

您的可执行文件是否需要cx_freeze未找到的库?

您可能需要指定其他选项,例如包含库... 调整cx_freeze documentation中的示例,您可以指定包含TKinter:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "simple_Tkinter",
    version = "0.1",
    description = "Sample cx_Freeze Tkinter script",
    options = {"build_exe": build_exe_options},
    executables = [Executable("the timer.py", base = base)])

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("guifoo.py", base=base)])

我知道我有很多有趣的问题让py2exe与PySide / PyQt4,matplotlib,numpy等一起工作。一些模块,比如matplotlib,甚至提供了一种列出构建/分发所需的所有数据文件的方法。应用程序(matplotlib.get_py2exe_datafiles())。 Enthought的TraitsUI解决方案利用glob来获取所需文件的目录。我的观点是,由于模块导入在某些库中可能是动态的,混乱的或黑魔法的,因此许多构建实用程序无法找到所有必需的资源。此外,一旦您的可执行文件正常工作,如果您在分发中发现您知道应用程序不需要的内容,您可以使用其他选项将其排除,这有助于减少分发中的膨胀。希望TKinter不会太难以开始工作 - 看起来StackOverflow上的其他人都很成功。

对不起,我没有坚如磐石的解决方案,但我正努力帮助我!祝你好运!

相关问题