Label

Listing 3 scripts/PYQT2/01_main_widget/02_label/main.py
 1from PyQt5.QtWidgets import (
 2    QMainWindow, QApplication, QLabel
 3)
 4
 5class MainWindow(QMainWindow, object):
 6    def __init__(self, parent=None):
 7        super(MainWindow, self).__init__(parent)
 8        # Create a label
 9        self.label = QLabel("This is a label!", self)
10        # Set the position of the label
11        self.label.move(50, 50)
12
13if __name__ == "__main__":
14    app = QApplication([])
15    mainWindow = MainWindow()
16    mainWindow.show()
17    app.exec_()
  • This example adds a QLabel widget to the basic window to display a text label.

  • QLabel is used to display simple text or images.