问题
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