The QLabel Widget

Understand how we add text and images to our window.

We will now use QLabel widgets to add extra functionality to our projects. To display text, pictures, or movies, a QLabel object serves as a non-editable placeholder. It can also label other widgets so their functions or titles can be specified. Plain text, hyperlinks, and rich text can all be displayed with QLabel widgets.

Using the QLabel widget

First, we start by importing the necessary modules from QtWidgets (QApplication, QWidget and, QLabel), QtGui (QPixmap), and sys. We must import the QtWidgets class to create the window, and because we will be utilizing the QLabel widget this time, we must include it in our import line. The QtGui module needs to be imported this time as well. QtGui handles numerous graphical aspects. A Qt class called QPixmap is explicitly designed for displaying images on screens.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy