Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PyQt5 – How to check visibility status of label ?

  • Last Updated : 26 Mar, 2020

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.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!