2019-06-13 13:33:11 1711瀏覽
今天千鋒扣丁學(xué)堂Python培訓(xùn)老師給大家分享一篇關(guān)于pyqt5實現(xiàn)工具欄文字圖片同時顯示的詳細介紹,希望對同學(xué)們學(xué)習(xí)Python開發(fā)有所幫助,下面我們一起來看一下吧。
import sys from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication from PyQt5.QtGui import QIcon from PyQt5.QtCore import Qt class Example(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): textEdit = QTextEdit() self.setCentralWidget(textEdit) exitAction = QAction(QIcon('images/exit.png'), 'Exit',self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(self.close) self.statusBar() menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(exitAction) toolbar = self.addToolBar('Exit') # toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # 文字圖片垂直排列 toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) # 文字圖片水平排列 toolbar.addAction(exitAction) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Main window') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進入Python全棧開發(fā)免費公開課】
查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>