PyQt5 How To Add Image In PyQt Window

In this PyQt5 article iam going to show you How To Add Image In PyQt Window. basically we are using QLabel and QPixmap classes for this. so there are four classes for handling image data, QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. The isQBitmap() function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture class is a paint device that records and replays QPainter commands.

 

 

 

Join PyQt5 Full Course for Free

PyQt5 Course

 

 

 

Also you can read more Python GUI articles in the below links

 

 

 

OK now the first thing we need some imports from PyQt5 and these are the imports that we need.

 

 

 

After that we are going to create our main Window class that extends from QDialog . and in the constructor of the class we need to initialize some requirements of the window . also we have called our initWindow() method in here.

 

 

 

After that we create our InitWindow() method and in that method we set our window icon, title and also we set our geometry also in this method first we create a QVBoxLayout  and after that we create a QLabel object ,  for adding image we need to create a QPixmap object, make sure that you have added an image to to your working directory.

 

 

 

Also every PyQt5 application must create an application object. 

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. 

 

 

 

 

Complete source code PyQt5 How To Add Image In PyQt Window

 

 

 

 

Run the complete code and this will be the result

PyQt5 How To Add Image In PyQt Window
PyQt5 How To Add Image In PyQt Window

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×