QLabel is a widget in the PyQt library that is used to display text or an image. It can be used to display text, such as a title or label for a form or dialog box, or to display an image, such as an icon or logo. The text or image displayed by a QLabel can be static or dynamic, and can be changed programmatically at runtime. QLabel also supports HTML formatting, enabling the creation of rich, formatted text labels. QLabel is a class in the PyQt5 library, which is a set of Python bindings for the Qt libraries used to create graphical user interfaces (GUIs). Here is an example of how to create a QLabel and display it in a window:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel

app = QApplication(sys.argv)
widget = QWidget()
widget.setWindowTitle("Label Example")

# create a QLabel
qlabel = QLabel(widget)
qlabel.setText("Hello World !")

# define the qlabel dimensions & position
qlabel.setGeometry(50 , 50 , 200 , 50)


In this example:

  1. we first import: the necessary modules from PyQt5,
  2. then create an instance of the QApplication class: which is required for any PyQt5 application.
  3. Next, we create a QLabel object: and set its text to "Hello, World!".
  4. Finally, we show the label: and run the application's event loop.
Younes Derfoufi

Leave a Reply