python编写windows exe程序,如何设置版本号及exe图标

经常用pyinstaller生成windows的exe程序,要设置版本号及图标非常简单,只要准备好以下的版本信息文件file_version_info.txt,还有一个图标,使用一行命令即可实现,操作流程如下:

1.版本配置文件格式如下,复制以下代码保存为file_version_info.txt

# UTF-8
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
  ffi=FixedFileInfo(
    # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
    # Set not needed items to zero 0.
    filevers=(6, 1, 7601, 17514),
    prodvers=(6, 1, 7601, 17514),
    # Contains a bitmask that specifies the valid bits 'flags'r
    mask=0x3f,
    # Contains a bitmask that specifies the Boolean attributes of the file.
    flags=0x0,
    # The operating system for which this file was designed.
    # 0x4 - NT and there is no need to change it.
    OS=0x40004,
    # The general type of file.
    # 0x1 - the file is an application.
    fileType=0x2,
    # The function of the file.
    # 0x0 - the function is not defined for this fileType
    subtype=0x0,
    # Creation date and time stamp.
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'040904B0',
        [StringStruct(u'CompanyName', u'Microsoft Corporation'),
        StringStruct(u'FileDescription', u'DiskPart'),
        StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
        StringStruct(u'InternalName', u'diskpart.exe'),
        StringStruct(u'LegalCopyright', u'© Microsoft Corporation. All rights reserved.'),
        StringStruct(u'OriginalFilename', u'diskpart.exe'),
        StringStruct(u'ProductName', u'Microsoft® Windows® Operating System'),
        StringStruct(u'ProductVersion', u'6.1.7601.17514')])
      ]),
    VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
  ]
)

 2.修改file_version_info.txt中以下字段,即可对版本及描述信息进行修改

filevers=(1, 18, 1026, 1),
prodvers=(1, 18, 1026, 1),

[StringStruct(u'CompanyName', u'Microsoft Corporation'),
StringStruct(u'FileDescription', u'DiskPart'),
StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
StringStruct(u'InternalName', u'diskpart.exe'),
StringStruct(u'LegalCopyright', u'© Microsoft Corporation. All rights reserved.'),
StringStruct(u'OriginalFilename', u'diskpart.exe'),
StringStruct(u'ProductName', u'Microsoft® Windows® Operating System'),
StringStruct(u'ProductVersion', u'6.1.7601.17514')])

3.准备好要设置exe图标,比如名字为logo.ico 

4.把要生成exe文件的py文件(如MainService.py)、logo.ico、file_version_info.txt放在同一个目录下,执行以下命令

pyinstaller --version-file=file_version_info.txt --icon=ico.ico --onefile --windowed MainService.py

即可生成带图标带版本信息的exe文件了

版本信息如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值