【问题标题】:wxPython - py2exe - exe file old windowwxPython - py2exe - exe文件旧窗口
【发布时间】:2013-05-17 09:06:08
【问题描述】:

我正在使用 py2exe 将使用 wxPython 制作的 GUI 应用程序转换为独立的单个 exe 文件。这就是我在 setup.py 中使用的:

from distutils.core import setup
import py2exe

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
        'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
        'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
            'tk84.dll']

setup(
options = {"py2exe": {"compressed": True, 
                      "optimize": 2,
                      "includes": includes,
                      "excludes": excludes,
                      "packages": packages,
                      "dll_excludes": dll_excludes,
                      "bundle_files": 1,
                      "dist_dir": "dist",
                      "skip_archive": False,
                      "ascii": False,
                      "custom_boot_script": '',
                     }
          },
zipfile = None,
windows=['script.py']
)

一切顺利,但我面临的问题是 UI 看起来很旧。就像Windows 97的界面什么的。这是图片:

【问题讨论】:

  • 直接运行是不是很好看?如果是这样,请尝试删除所有 excludesdll_excludes(除非您确实需要排除这些),然后看看它是否有任何改变。
  • 直接运行看起来不错。删除了所有排除和 dll_excludes 但仍然没有。

标签: python user-interface py2exe


【解决方案1】:

我也遇到过这个问题,找到了解决办法。
要让 Windows 控件看起来正常,首先您必须将清单插入目标可执行文件,就像 here 提到的那样。

manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
    version="0.64.1.0"
    processorArchitecture="x86"
    name="Controls"
    type="win32"
/>
<description>Your Application</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
"""

setup(
    windows = [
        {
            "script": "yourapplication.py",
            "icon_resources": [(1, "yourapplication.ico")],
            "other_resources": [(24,1,manifest)]
        }
    ],
      data_files=["yourapplication.ico"]
)

其次,您必须获得相应的运行时 dll。
要获取清单和dll,您可以下载Dropbox并安装,然后进入安装的文件夹,使用Manifest View从Dropbox.exe和子文件夹Microsoft.VC90.CRT中获取dll(将此文件夹保留在您的应用程序中区)。以下是我从 Dropbox.exe 得到的。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <asmv3:windowsSettings
            xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
    </asmv3:application>
    <assemblyIdentity
        version="2.6.25.0"
        processorArchitecture="X86"
        name="Dropbox"
        type="win32"
        />
    <description>*</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.VC90.CRT"
                version="9.0.30729.1"
                processorArchitecture="x86"
                publicKeyToken="1fc8b3b9a1e18e3b"
                />
        </dependentAssembly>
    </dependency>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="X86"
                publicKeyToken="6595b64144ccf1df"
                language="*"
                />
        </dependentAssembly>
    </dependency>
</assembly>

然后目标exe运行得很好。

【讨论】:

    【解决方案2】:

    这个脚本适合我:

    from distutils.core import setup
    
    import py2exe
    
    setup(
            options = {'py2exe': {'bundle_files': 1,
                                  'dll_excludes': ['w9xpopen.exe'],
                                  'excludes': ['pywin', 'pywin.debugger',
                                               'pywin.debugger.dbgcon',
                                               'pywin.dialogs',
                                               'pywin.dialogs.list',
                                               'Tkconstants', 'Tkinter', 'tcl']}},
            windows = [{'script': 'script.py'}],
            zipfile = None,
        )
    

    如果这对你有用,也许你可以试试。因为'w9xpopen.exe' 只需要旧的 Windows 系统,即 Windows 95 和 98,您可以添加 'dll_excludes': ['w9xpopen.exe']。这可能有助于解决您的问题。

    【讨论】:

    • 添加清单允许指定要使用的控件wxPython siteversion="6.0.0.0"version="7.0.0.0" 应该可以工作。
    猜你喜欢
    • 2014-09-17
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多