Skip to content
Related Articles

Related Articles

PyQt5 – Add Label to StatusBar

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 22 Apr, 2020

In this article we will see how to add label to a status bar. We can set text to status bar by using showMessage method.

Label and StatusBar ?
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. A status bar is a horizontal bar, usually at the bottom of the screen or window, showing information about a document being edited or a program running.

In order to do this we will do following steps :

1. Create a label
2. Add text to label
3. Create object of status bar
4. Add label to status bar

Code :




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  the geometry of window
        self.setGeometry(60, 60, 600, 400)
  
        # setting status bar message
        self.statusBar().showMessage("This is status bar")
  
        # setting  border and padding with different sizes
        self.statusBar().setStyleSheet("border :3px solid black;")
  
        # creating a label widget
        self.label_1 = QLabel("Label 1")
  
  
        # setting up the border
        self.label_1.setStyleSheet("border :2px solid blue;")
  
        # adding label to status bar
        self.statusBar().addPermanentWidget(self.label_1)
        # 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())


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!