# -*- coding: utf-8 -*-
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class StatusDemo(QMainWindow):
def __init__(self, parent = None):
super(StatusDemo, self).__init__(parent)
bar = self.menuBar()
bar.setNativeMenuBar(False)
file = bar.addMenu("File")
file.addAction("show")
file.triggered[QAction].connect(self.processTrigger)
self.setCentralWidget(QTextEdit())
self.statusBar = QStatusBar()
self.setWindowTitle("QStatus 例子")
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)
demo = StatusDemo()
demo.show()
sys.exit(app.exec_())
(2)
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class StatusBarWidget(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
#垂直布局
layout=QVBoxLayout()
statusBar = QStatusBar()
statusBar.showMessage(" 菜单选项被点击了",3000)
layout.addWidget(statusBar)
self.setLayout(layout)