【问题标题】:cx freeze set custom .exe iconcx 冻结设置自定义.exe 图标
【发布时间】:2017-04-11 21:29:57
【问题描述】:

我正在使用 cx_freeze 将 .py 文件转换为 .exe 文件。我当前的安装文件正在运行,但我似乎无法更改它,以便我的 .exe 文件具有我制作的自定义图标。我尝试了几种不同的方法,但似乎都没有奏效。任何建议都会非常有帮助。感谢您的宝贵时间。

试一试

import sys
from cx_Freeze import setup, Executable

include_files = ['autorun.inf']

base = None

if sys.platform == "win32":
    base = "Win32GUI"

setup(name = "Calculator",
        version = "0.1",
        description = "Simple Calculator",
        options = {'build_exe':{'include_files':include_files, 
                   'icon':'icon.ico'}},
        executables=[Executable("main.py", base = base)])

尝试二

import sys
from cx_Freeze import setup, Executable

include_files = ['autorun.inf']

base = None

if sys.platform == "win32":
    base = "Win32GUI"

setup(name = "Calculator",
        version = "0.1",
        description = "Simple Calculator",
        options = {'build_exe':{'include_files':include_files}},
        executables=[Executable("main.py", base = base, icon = 'icon.ico')])

【问题讨论】:

    标签: python-3.x cx-freeze


    【解决方案1】:

    这个方法应该有效:

    import sys
    from cx_Freeze import setup, Executable
    
    include_files = ['autorun.inf']
    
    base = None
    
    if sys.platform == "win32":
        base = "Win32GUI"
    
    exe = Executable(script='main.py', base = base, icon='icon.ico')
    
    
    setup(name = "Calculator",
            version = "0.1",
            description = "Simple Calculator",
            options = {'build_exe':{'include_files':include_files}},
            executables = [exe])
    

    【讨论】:

    • 成功了!谢谢!你能向我解释一下为什么这行得通而我的第二次尝试没有?
    • @laxer 你只有一个小问题。在executables=[Executable("main.py", base = base, icon = 'icon.ico')])线上,你必须输入你忘记的script = 'main.py'
    • @Vagif 我只是认为这会产生错误,但感谢您的回答和描述。这很有帮助!
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多