How to set an icon for an exe file using pyinstaller
-
Hi,
I'm having an issue with setting an icon for exe file. When I run this command the icon set for the .exe file does not show after the compilation.pyinstaller EDS_main.py --onefile --windowed --icon=transparent.ico
. Any help with what I'm wrong thanks in advance. -
I quote from this great page:
The icon used for the window isn't determined by the icons in the executable file, but by the application itself. To show an icon on our window we need to modify our simple application a little bit, to add a call to .setWindowIcon().
pythonfrom PyQt6 import QtWidgets, QtGui import sys class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Hello World") l = QtWidgets.QLabel("My simple app.") l.setMargin(10) self.setCentralWidget(l) self.show() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) app.setWindowIcon(QtGui.QIcon('hand.ico')) w = MainWindow() app.exec()
Here we've added the .setWindowIcon call to the app instance. This defines a default icon to be used for all windows of our application. You can override this on a per-window basis if you like, by calling .setWindowIcon on the window itself.