【问题标题】:How to make a .exe for Python with good graphics?如何为 Python 制作具有良好图形的 .exe?
【发布时间】:2011-04-15 10:21:39
【问题描述】:

我有一个 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 的那个一样好?

【问题讨论】:

  • 那怎么了?禁用的工具栏图标?
  • 是的,还有按钮的类型。

标签: python graphics wxpython py2exe


【解决方案1】:

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

# -*- 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"],
)

感谢您的快速回答:)

【讨论】:

  • 在我使用这个清单之前,我尝试过的所有其他清单都有运行时错误。谢谢!!!!
【解决方案2】:

我发现当我在 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 与 ye olde VS2003),还有一个适用于 2.6+ 版本的 Python 相关清单。 Robin Dunn 似乎已经修复了 wxPython 的最新版本,因此您不需要包含那个烦恼,但是如果您不使用 wx,那么您在尝试创建二进制文件时可能会遇到这个问题。 py2exe 网站和 wxPython wiki 都讨论了这个问题以及如何创建 SxS 清单。

【讨论】:

    【解决方案3】:

    我假设您的意思是工具栏和按钮的视觉风格。您需要将清单文件添加到 EXE 文件或作为单独的文件,以便 Windows 应用最新 comctl32.dll 版本的现代风格。

    查看 MSDN 上的 Using Windows XP Visual Styles With Controls on Windows Forms。阅读有关创建“.exe.manifest”文件的相关部分。

    可以在wxPython site 找到更多特定于 py2exe 的教程。他们解释了如何使用 setup.py 来包含必要的清单文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 2019-12-29
      • 1970-01-01
      相关资源
      最近更新 更多