I have a PySide GUI app (written in Python 3, running on Windows 7 Pro) in which I’m setting the application icon as follows:
class MyGui(QtGui.QWidget):
def __init__(self):
super(MyGui, self).__init__()
...
self.setWindowIcon(QtGui.QIcon('MyGui.ico'))
if os.name == 'nt':
# This is needed to display the app icon on the taskbar on Windows 7
import ctypes
myappid = 'MyOrganization.MyGui.1.0.0' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
...
I got that ctypes
stuff from this answer. If I remove those lines then the Python icon is displayed in the taskbar when I execute python MyGui.py
.
With those lines included everything looks great, with the correct icon on the window and the taskbar. However, when I package the gui using cxfreeze both the window and taskbar icons change to the generic windows .exe icon.
I’m using cxfreeze.bat
to package the app, using the instructions found here, including the --icon
switch. Using that switch makes the generated exe have the right icon when viewed in explorer. However, the application window, and taskbar, don’t show the icon when I launch the app. I’ve tried copying the .ico file to the same directory as the .exe but that doesn’t help.
I get the same behavior on both Windows 7 & 8. The curious thing is that if I pin the app to the taskbar, the taskbar icon is displayed correctly, but the window icon is still the generic exe icon.
How do I get the icon to display correctly?