一沟堡、狀態(tài)欄
狀態(tài)欄是用來顯示應(yīng)用的狀態(tài)信息的組件侧但。
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('Ready')
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Statusbar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
知識(shí)點(diǎn):
self.statusBar().showMessage('Ready')
二矢空、菜單欄
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menubar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
知識(shí)點(diǎn):
def initUI(self):
##創(chuàng)建一個(gè)Action航罗,并為Action按鍵添加狀態(tài)信息,并鏈接按鍵行為
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
##建立狀態(tài)欄
self.statusBar()
##建立菜單
menubar = self.menuBar()
##添加菜單File按鈕屁药,并為File按鈕鏈接Action子菜單
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menubar')
self.show()
由此粥血,其實(shí)是可以實(shí)現(xiàn)將多個(gè)程序合并到一個(gè)ui界面的功能了。
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
import helloworld
import myname
print('e')
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
helloworldAction = QAction(QIcon('web.png'), '&HelloWorld', self)
helloworldAction.setShortcut('Ctrl+H')
helloworldAction.setStatusTip('Print:hello, world')
helloworldAction.triggered.connect(helloworld.helloworld)
mynameAction = QAction(QIcon('web.png'), '&Test', self)
mynameAction.setShortcut('Ctrl+M')
mynameAction.setStatusTip('Print:my name')
mynameAction.triggered.connect(myname.myname)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&Test')
fileMenu.addAction(helloworldAction)
fileMenu.addAction(mynameAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menubar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
完美酿箭。