How to Add Text and Image in PyQt5 Label

In this article we want to learn How to Add Text and Image in PyQt5 Label, first of all let’s talk about PyQt5. so PyQt5 is popular Python library for creating desktop applications, and Label is one of the important widget in PyQt5 that we can use for displaying text or adding images. even you can use PyQt5 label for displaying GIF images.

 

 

 

First of all if you have not installed PyQt5, you need to install and you can use pip for that.

 

 

To start, we need to import the required modules from PyQt5, these are our imports.

 

 

 

After that we need to create an instance of the QApplication class to manage the GUI event loop. and than we creates a QMainWindow instance as the main window container, also if you see we have added some methods like setWindowTitle(), it is used for setting the window title, also setGeometry(), it is used for setting the x,y, width and height of the window.

 

 

 

This code is used for creating the label and setting the x,y,width and height of the window.

 

 

 

For displaying an image, we need to use QPixmap class from the QtGui module. this is an example that how you can add an image to QLabel:

 

 

For displaying the main window and start the application’s event loop, you can use this code.

 

 

 

This is the complete code for this article

 

 

 

 

 

Run the code and this will be the result

How to Add Text and Image in PyQt5 Label
How to Add Text and Image in PyQt5 Label

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×