PyQt5--ToolBar
1 # -*- coding:utf-8 -*- 2 ''' 3 Created on Sep 14, 2018 4 5 @author: SaShuangYiBing 6 ''' 7 import sys 8 from PyQt5.QtWidgets import QApplication,QMainWindow,QAction,qApp 9 from PyQt5.QtGui import QIcon 10 11 class New_test(QMainWindow): 12 def __init__(self): 13 super().__init__() 14 self.initUI() 15 16 def initUI(self): 17 exitAction = QAction(QIcon('tools.png'),'Exit',self) 18 exitAction.setShortcut('Ctrl+Q') #注意该组合快捷键需要连着写,不能有空格,否则会导致快捷键失效 19 exitAction.triggered.connect(qApp.quit) 20 21 self.toolbar = self.addToolBar('Exit') 22 self.toolbar.addAction(exitAction) 23 24 self.setGeometry(300,300,250,150) 25 self.setWindowTitle('Tools Bar') 26 self.show() 27 28 if __name__ == "__main__": 29 app = QApplication(sys.argv) 30 ex = New_test() 31 sys.exit(app.exec_())