Python cx-freeze 快捷方式图标
Posted
技术标签:
【中文标题】Python cx-freeze 快捷方式图标【英文标题】:Python cx-freeze shortcut icon 【发布时间】:2018-07-27 15:09:37 【问题描述】:我使用 cx-freeze 通过制作 msi 安装文件来分散应用程序。在 setup.py 脚本中,我指定了需要放在桌面上的快捷方式。但是,快捷方式图标为空白。 setup.py 包含以下代码。我做错了什么?
import ...
....
shortcut_table = [
("DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"PhotonFileEditor", # Name
"TARGETDIR", # Component_
"[TARGETDIR]\PhotonEditor.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
"[TARGETDIR]photonsters.ico", # Icon
0, # IconIndex
None, # ShowCmd
"TARGETDIR", # WkDir
)
]
# Now create the table dictionary
msi_data = "Shortcut": shortcut_table
#msi_data = "Shortcut": shortcut_table, "Icon": icon_table
# Change some default MSI options and specify the use of the above defined tables
bdist_msi_options = 'data': msi_data
....
【问题讨论】:
不太确定。但是由于已经 2 天没有回复,您是否检查过此行不需要反斜杠? “[TARGETDIR]\photonsters.ico”。此外,“Icon”字段实际上是 Windows Installer 文档中的“Icon_”,即它是名为“Icon”的表的外键。 docs.microsoft.com/en-us/windows/desktop/msi/icon-table 【参考方案1】:谢谢,这解决了我的问题!我的代码的 sn-p:
快捷方式:
shortcut_table = [
("DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"PhotonFileEditor",# Name
"TARGETDIR", # Component_
"[TARGETDIR]\PhotonEditor.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
"", # Icon (Use
0, # IconIndex
None, # ShowCmd
"TARGETDIR", # WkDir
)
]
设置:
setup ( name = "PhotonFileEditor",
version = "0.1",
author= "Photonsters",
url="https://github.com/Photonsters",
description = "Photon File Editor",
options = "build_exe": build_exe_options,"bdist_msi": bdist_msi_options,
executables = [Executable(script="PhotonEditor.py",
base=base,icon="PhotonEditor.ico",)]
)
【讨论】:
【参考方案2】:您是否尝试过:
将icon
参数添加到您的Executable
?
删除shortcut_table
的Target
中的反斜杠,并删除Icon
和IconIndex
条目?
import ...
....
shortcut_table = [
("DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"PhotonFileEditor", # Name
"TARGETDIR", # Component_
"[TARGETDIR]PhotonEditor.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
"TARGETDIR", # WkDir
)
]
# Now create the table dictionary
msi_data = "Shortcut": shortcut_table
#msi_data = "Shortcut": shortcut_table, "Icon": icon_table
# Change some default MSI options and specify the use of the above defined tables
bdist_msi_options = 'data': msi_data
executables = [Executable(....,
icon='photonsters.ico')]
....
setup(....,
executables=executables)
您是否在构建步骤后检查了图标文件photonsters.ico
是否存在于build_dir
目录中?
【讨论】:
以上是关于Python cx-freeze 快捷方式图标的主要内容,如果未能解决你的问题,请参考以下文章