如何为Python制作一个具有良好图形效果的.exe?

发布于 2024-09-24 05:51:59 字数 644 浏览 4 评论 0原文

我有一个 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。 alt text

如何使 .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.
alt text

How can I make the .exe one be as good as the one that runs thought python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我早已燃尽 2024-10-01 05:51:59

我假设您指的是工具栏和按钮的视觉样式。您需要将清单文件添加到 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.

束缚m 2024-10-01 05:51:59

我安装的最终设置是这样的:

# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
from glob import glob

sys.argv.append('py2exe')


manifest = """
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
     type='win32'
     name='Microsoft.VC90.CRT'
     version='9.0.21022.8'
     processorArchitecture='*'
     publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*" />
    </dependentAssembly>
  </dependency>
</assembly>
"""

setup(
##    data_files = data_files,
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "SoundLog.py", 'other_resources': [(24,1,manifest)]}],
    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"],
)

感谢您的快速回答:)

The final setup that I mounted was this:

# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
from glob import glob

sys.argv.append('py2exe')


manifest = """
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
     type='win32'
     name='Microsoft.VC90.CRT'
     version='9.0.21022.8'
     processorArchitecture='*'
     publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*" />
    </dependentAssembly>
  </dependency>
</assembly>
"""

setup(
##    data_files = data_files,
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "SoundLog.py", 'other_resources': [(24,1,manifest)]}],
    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"],
)

Thanks for the quick answers :)

咽泪装欢 2024-10-01 05:51:59

我发现在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文