PyQt set icon
The application icon is a small image that will be displayed at the left end of the title bar. Here's how to display the application icon.
First, in the folder, save the image file that you want to use as an icon, as shown below.
Related course: Create Desktop Apps with Python PyQt5
Put the application icon.
import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QIcon class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle('Icon') self.setWindowIcon(QIcon('web.png')) self.setGeometry(300, 300, 300, 200) self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec_())
While floating a window, a small icon appeared on the left side of the title bar.
setWindowIcon() method allows you to set the application icon. To do this, we created a QIcon object. In
QIcon(), type the image ('web.png') to be shown.
If you have stored the image files separately in a different folder, you can enter the path.
self.setGeometry(300, 300, 300, 200)
setGeometry() method determines the position and size of the window. The preceding two parameters determine the x and y positions of the window, and the two parameters after each determine the width and height of the window.
This method is the same as the
resize() methods used in the window floating example as one.