Open In App

PyQt5 – How to check visibility status of label ?

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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):
        super().__init__()
  
  
        # set the title
        self.setWindowTitle("Python")
  
        # 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
        self.label_1.setVisible(True)
  
        # show all the widgets
        self.show()
  
  
# 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
print(visible)
  
# start the app
sys.exit(App.exec())


Output :

True



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads