pyqt5 實現工具欄文字圖片同時顯示
更新時間:2019年06月13日 11:29:09 作者:FollowWind
今天小編就為大家分享一篇pyqt5 實現工具欄文字圖片同時顯示的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
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_())
以上這篇pyqt5 實現工具欄文字圖片同時顯示就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
python完成FizzBuzzWhizz問題(拉勾網面試題)示例
這篇文章主要介紹了python完成FizzBuzzWhizz問題(拉勾網面試題)示例,需要的朋友可以參考下2014-05-05