How do you add a status bar in PyQt5?

In PyQt5, you can add a status bar using the statusBar() method of the QMainWindow class. Here is a simple example:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow

class MainApp(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.initUI()
    
    def initUI(self):
        self.statusBar().showMessage('Ready')
        
        self.setWindowTitle('Status Bar Example')
        self.setGeometry(100, 100, 400, 300)
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainApp = MainApp()
    mainApp.show()
    sys.exit(app.exec_())

In this example, we have created a MainApp class that inherits from QMainWindow. In the initUI method, we used self.statusBar().showMessage(‘Ready’) to add a status bar and display the message “Ready”. Finally, we instantiated QApplication and MainApp class, and launched the application. When you run this code, you will see a window with a status bar.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds