When we design a PyQt5 application we see an icon on the top left corner, by default it looks like this :
In this tutorial, we will see how to change the icon according to the user need, in order to do this we use setWindowIcon() method and to load the icon QIcon will be used which belongs to QtGui class.
Syntax : setWindowIcon(QtGui.QIcon(‘icon.png’)) Argument : It takes file name if file is in same folder else file path.
Code :
Python3
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from PyQt5 import QtGui
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowIcon(QtGui.QIcon( 'logo.png' ))
self .setWindowTitle("Icon")
self .setGeometry( 0 , 0 , 400 , 300 )
self .label = QLabel("Icon is set ", self )
self .label.move( 100 , 100 )
self .label.setStyleSheet("border: 1px solid black;")
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output : 
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
29 Dec, 2022
Like Article
Save Article