Python cx-freeze快捷方式图标

时间:2018-07-27 15:09:38

标签: python windows-installer cx-freeze distutils desktop-shortcut

我使用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 个答案:

答案 0 :(得分:1)

谢谢,这解决了我的问题!我的代码段:

快捷方式:

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

答案 1 :(得分:0)

  1. 您是否尝试过:

    • icon参数添加到您的Executable吗?
    • 要删除Target的{​​{1}}中的反斜杠,并删除shortcut_tableIcon项?

      IconIndex
  2. 在构建步骤之后,您是否检查过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