Wednesday, July 8, 2026
HomeLanguagesPyQt5 – How to hide label | label.setHidden method

PyQt5 – How to hide label | label.setHidden method

In this article, we will see how we can hide the Label in the PyQt5 application. 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 another widget. In order to hide the label we use setHidden() method, this method allows user to set if the widget should be visible or hidden, it belongs to the QWidget class.

Syntax : label.setHidden(True) Argument : It takes bool as an argument.

Code : 

Python3




# importing the required libraries
 
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from PyQt5.QtGui import *
import sys
 
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
 
 
        # set the title
        self.setWindowTitle("Label")
 
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
 
        # creating a label widget
        self.label_1 = QLabel("Normal Label", self)
 
        # moving position
        self.label_1.move(100, 100)
 
        # setting up border
        self.label_1.setStyleSheet("border: 1px solid black;")
 
        # creating a label widget
        self.label_2 = QLabel("Hidden Label", self)
 
        # moving position
        self.label_2.move(100, 150)
 
        # setting up border
        self.label_2.setStyleSheet("border: 1px solid black;")
 
        # hiding the label
        self.label_2.setHidden(True)
 
 
        # show all the widgets
        self.show()
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
# start the app
sys.exit(App.exec())


Output : pyqt-hide-label As we can see the label 2 is hidden in the output window.

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12016 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6977 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS