2014-02-25 45 views
1

我已经在这个地方搜索了这个答案,但是我找不到答案。我有一个Python脚本(3.3),它与tkinter有一个接口。我用cx_freeze创建了一个可执行文件,它有一个包含一些文件和文件夹的构建文件夹。我双击.exe文件并没有发生任何事情。我正在使用以下设置:用cx_freeze为tkinter接口创建.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)]) 

如果我只是打开我的代码并运行它的界面完美地工作。我在构建时没有收到任何错误消息(至少没有我能看到的... btw,我如何验证它?)。任何想法可能是什么问题?或任何其他替代模块?

谢谢! :)

+0

如果您在命令提示符下运行该exe,会发生什么情况? –

回答

3

我从编译输出/日志,使之成为一个评论,但我没有信誉尚未...

任何警告/错误?

什么时候在命令提示符下运行可执行文件?

您的可执行文件需要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 Traits的解决方案UI利用glob来获取所需文件的目录。我的观点是,因为某些库中的模块导入可能是动态的,杂乱的或黑魔法的,所以许多构建实用程序无法找到所有必需的资源。此外,一旦你的可执行文件正在工作,如果你发现你的应用程序不需要的发行版中的东西,你可以用其他选项排除它,这有助于减少发行版中的膨胀。希望TKinter不会太难以工作 - 看起来StackOverflow上的其他人是成功的。

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

+1

非常感谢您的回答。我发现了这个问题,并且感觉有点笨拙......我没有在最后添加root.mainloop()......这是一个新手的错误,但我一定会牢记build_exe_options部分!再次感谢!! :) – rodrigocf