如何为Python制作一个具有良好图形效果的.exe?
我有一个 Python 应用程序,我决定创建一个 .exe 来执行它。
这是我用来执行 .exe 的代码:
# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "SoundLog.py"}],
zipfile = None,
packages=[r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar", r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins"],
)
但是当我使用 .exe 运行应用程序时,图形有很大不同。
在下图中,您可以看到左侧运行的是 python,右侧运行的是 .exe。
如何使 .exe 与运行 python 的一样好?
I have a Python application and I decided to do a .exe to execute it.
This is the code that I use to do the .exe:
# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "SoundLog.py"}],
zipfile = None,
packages=[r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar", r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins"],
)
But when I run my application with the .exe, the graphics are quite different.
In the image bellow you can see the application running thought python at the left and running thought the .exe at the right.
How can I make the .exe one be as good as the one that runs thought python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您指的是工具栏和按钮的视觉样式。您需要将清单文件添加到 EXE 文件或作为单独的文件,以便 Windows 应用最新 comctl32.dll 版本的现代风格。
查看 在 Windows 窗体上使用 Windows XP 视觉样式和控件MSDN 上的。阅读有关创建“.exe.manifest”文件的相关部分。
可以在 wxPython 站点 找到更多特定于 py2exe 的教程。他们解释了如何使用 setup.py 包含必要的清单文件。
I assume you mean the visual style of the toolbar and buttons. You need to add a manifest file to the EXE file or as a separate file so that Windows applies the modern style of recent comctl32.dll versions.
Check out Using Windows XP Visual Styles With Controls on Windows Forms on MSDN. Read the relevant part about creating the ".exe.manifest" file.
A more py2exe-specific tutorial can be found over at the wxPython site. They explain how to use setup.py to include the necessary manifest file.
我安装的最终设置是这样的:
感谢您的快速回答:)
The final setup that I mounted was this:
Thanks for the quick answers :)
我发现在 Windows 7 上使用 Python 2.6 时不需要清单文件。但在 XP 和 Vista 上使用 Python 2.5 时确实需要它。如果您使用 GUI2Exe,您所需要做的就是选中一个小复选框来包含它。
请参阅以下教程:
http ://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/31/another-gui2exe -tutorial-build-a-binary-series/
由于 Windows 上编译器的切换(即 VS2008 与旧的 VS2003),还有一个与 2.6+ 版本相关的 Python 相关清单。 Robin Dunn 似乎已经修复了 wxPython 的最新版本,因此您不需要包含这个烦恼,但如果您不使用 wx,那么当您尝试创建二进制文件时,您可能会遇到这个问题。 py2exe 网站和 wxPython wiki 都讨论了这个问题以及如何创建 SxS 清单。
I found that I didn't need the manifest file when I used Python 2.6 on Windows 7. But I did need it when I used Python 2.5 on XP and Vista. If you use GUI2Exe, all you need to do is check a little checkbox to include it.
See the following tutorials:
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/31/another-gui2exe-tutorial-build-a-binary-series/
There's also a Python-related manifest for anything 2.6+ due to the switch in compilers on Windows (i.e. VS2008 vs ye olde VS2003). Robin Dunn seems to have fixed the latest build of wxPython so you don't need to include that annoyance, but if you're NOT using wx, then you'll probably run into this issue when you try to create a binary. The py2exe website and the wxPython wiki both talk about the issue and how to create the SxS manifest.