Open In App
Related Articles

How to create Label widget in PyQt5 ?

Like Article
Save Article
Report issue
While designing any GUI (Graphical User Interface) there is a need to display plain text on screen, in order to do so Label widget is used in PyQt5. A label is a graphical control element which displays text on a form. It is usually a static control; having no interactivity. A label is generally used to identify a nearby text box or other widget. Some labels can respond to events such as mouse clicks, allowing the text of the label to be copied, but this is not standard user-interface practice. To use Labels in PyQt5 we have to import QLabel from PyQt5.QtWidgets , below is the syntax to do so.
from PyQt5.QtWidgets import QLabel
After importing Qlabel, we can create Labels in our PyQt5 application. Syntax :
self.label_name = QLabel(Info, self)
Here Info can be any text of string type. Below is the Python implementation –
# importing the required libraries
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
        # creating a label widget
        # by default label will display at top left corner
        self.label = QLabel('This is label', self)
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output : pyqt-label

Last Updated : 26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Similar Reads