其他分享
首页 > 其他分享> > PyQt5基础学习-QStatusBar(状态栏) 1..setStatusBar(设置状态栏) 2.self.statusBar.showMessage(显示内容)

PyQt5基础学习-QStatusBar(状态栏) 1..setStatusBar(设置状态栏) 2.self.statusBar.showMessage(显示内容)

作者:互联网

通过点击菜单栏的按钮,在状态栏显示5秒的文字

"""
创建和使用状态栏
"""

import sys, math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class StatusBar(QMainWindow):
    def __init__(self):
        super(StatusBar, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("状态栏演示")
        self.resize(300, 200)

        bar = self.menuBar()
        #添加目录
        file = bar.addMenu("File")
        #添加动作
        file.addAction("show")
        #对菜单添加动作 
        file.triggered.connect(self.processTrigger)
        self.setCentralWidget(QTextEdit())
        self.statusBar = QStatusBar()
        self.setStatusBar(self.statusBar)

    def processTrigger(self, q):
        if q.text() == "show":
            self.statusBar.showMessage(q.text() + "菜单被点击了", 5000)



if __name__ == "__main__":
    app = QApplication(sys.argv)

    main = StatusBar()
    main.show()

    sys.exit(app.exec_())

 

标签:__,状态栏,..,statusBar,self,PyQt5,import
来源: https://www.cnblogs.com/hyq-lst/p/15859586.html