PyQt5 – How to add image in window ?

In this article, we will see how to add image to a window. The basic idea of doing this is fist of all loading the image using QPixmap and adding the loaded image to the Label then resizing the label according to the dimensions of the image, although the resizing part is optional.

In order to use Qpixmap and other stuff we have to import following libraries:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap
import sys


For loading image :
Syntax :

pixmap = QPixmap('image.png')

Argument : Image name if image is in same folder else file path.
For adding image to label :
Syntax :


Argument : It takes QPixmap object as argument.

Code :





# importing the required libraries
from PyQt5.QtWidgets import * 
from PyQt5.QtGui import QPixmap
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
        # creating label
        self.label = QLabel(self)
        # loading image
        self.pixmap = QPixmap('image.png')
        # adding image to label
        # Optional, resize label to image size
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app


Output :

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.