Skip to content
Related Articles
Open in App
Not now

Related Articles

PyQt5 – How to check visibility status of label ?

Improve Article
Save Article
  • Last Updated : 26 Mar, 2020
Improve Article
Save Article

We can set visibility status of label using setVisible() method in PyQt5. In order to check the visibility status of any label we will use isVisible() method, this will return True or False by checking if the label is visible or not.

Note : If this method is used inside the constructor it will always return False as once the main-window/parent is visible only then the label visible property is changed to true.

Syntax : label.isVisible()

Argument : It takes no argument.

Return : It returns bool.

Code :

# importing the required libraries
from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # creating a label widget
        self.label_1 = QLabel("Label", self)
        # moving position
        self.label_1.move(0, 0)
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid black;")
        # setting visibility status
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# getting visibility status
visible = str(window.label_1.isVisible())
# printing visibility status of label
# start the app

Output :


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!