效果如下:
代码如下:
1 #!/usr/bin/python3 2 # -*- coding: utf-8 -*- 3 4 """ 5 This program creates a skeleton of 6 a classic GUI application with a menubar, 7 toolbar, statusbar, and a central widget. 8 9 """ 10 11 import sys 12 from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication 13 from PyQt5.QtGui import QIcon 14 15 16 class Example(QMainWindow): 17 18 def __init__(self): 19 super().__init__() 20 21 self.initUI() 22 23 def initUI(self): 24 25 textEdit = QTextEdit() 26 self.setCentralWidget(textEdit) 27 28 exitAct = QAction(QIcon('picturesexit24.png'), 'Exit', self) 29 exitAct.setShortcut('Ctrl+Q') 30 exitAct.setStatusTip('Exit application') 31 exitAct.triggered.connect(self.close) 32 33 self.statusBar() 34 35 menubar = self.menuBar() 36 fileMenu = menubar.addMenu('&File') 37 fileMenu.addAction(exitAct) 38 39 toolbar = self.addToolBar('Exit') 40 toolbar.addAction(exitAct) 41 42 self.setGeometry(300, 300, 350, 250) 43 self.setWindowTitle('Main window') 44 self.show() 45 46 47 if __name__ == '__main__': 48 49 app = QApplication(sys.argv) 50 ex = Example() 51 sys.exit(app.exec_())