Window Icon Not Displaying when Frozen with cx_Freeze

会有一股神秘感。 提交于 2020-12-13 07:29:04

问题


I’m using Python 3.6, PyQt5, and cx_Freeze in a Windows environment. The portion of code I use to display the icon on the main window and children windows is:

if getattr(sys, 'frozen', False): # If frozen with cx_Freeze
    homePath = os.path.dirname(sys.executable)
else: # Otherwise, if running unfrozen (e.g., within Spyder)
    homePath = os.path.dirname(__file__)
iconFileName = os.path.join(homePath, 'iconLarge.ico')
setWindowIcon(QIcon(iconFileName))

The frozen program defaults to a Windows-chosen icon instead of the icon I designated in the code. However, the unfrozen script displays the iconLarge.ico as I expect it to.

All solutions I have found so far are when using PyQt4 instead of PyQt5, and those solutions either do not apply to PyQt5 or did not solve the issue. Here is the code from setup.py that identifies the icon file:

exe=Executable(script="mycode.py", base = "Win32GUI", icon = "iconLarge.ico")

cx_Freeze puts the file iconLarge.ico in the main folder of the frozen build, which is where I expect it to be. The rest of the frozen application runs exactly as it should.

Suggestions on how to get the window icon to appear when freezing with cx_Freeze?

来源:https://stackoverflow.com/questions/48846219/window-icon-not-displaying-when-frozen-with-cx-freeze

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!