I have set the icon for my PyQt application using self.setWindowIcon(QtGui.QIcon('icon.png'))
and it works fine when I run my code in PyCharm.
Next I converted my application to one file with PyInstaller:
pyinstaller.exe --onefile --windowed opc.py --name myapps
However, when running the executable the icon is not shown. What am I doing wrong ?
On left site code from PyCharm, on right site from one file (pyinstaller.exe --onefile --windowed opc.py --name myapps). Why is not the same ? I want *.png icon because is transparent.
The icon displayed when running an executable on Windows comes from the executable file itself. To bundle an icon with your application you need to specify the icon when building with pyinstaller.exe
by passing the --icon
parameter. For example:
pyinstaller.exe --onefile --windowed --name myapps --icon=icon.ico opc.py
Note that unlike for setWindowIcon()
the icon file must be in .ico
format, so you will need to convert it from the .png
first.
If you want to use the PyQt call to set the icon you will need to bundle the icon file into the executable, which can be done using a PyInstaller spec file. A walkthrough of the process of creating and modifying the spec file is in this previous answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With