PyQt5 – Add Label to StatusBar
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__()
self .setWindowTitle( "Python" )
self .setGeometry( 60 , 60 , 600 , 400 )
self .statusBar().showMessage( "This is status bar" )
self .statusBar().setStyleSheet( "border :3px solid black;" )
self .label_1 = QLabel( "Label 1" )
self .label_1.setStyleSheet( "border :2px solid blue;" )
self .statusBar().addPermanentWidget( self .label_1)
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Share your thoughts in the comments
Please Login to comment...