PyQt5中的菜单和工具栏

来源:互联网 发布:普瑞软件 编辑:程序博客网 时间:2024/05/04 12:33

http://www.cnblogs.com/archisama/p/5450834.html

#!/usr/bin/python3# -*- coding: utf-8 -*-"""ZetCode PyQt5 tutorial This program creates a skeleton ofa classic GUI application with a menubar,toolbar, statusbar, and a central widget. author: Jan Bodnarwebsite: zetcode.com last edited: January 2015"""import sysfrom PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplicationfrom PyQt5.QtGui import QIconclass Example(QMainWindow):    def __init__(self):        super(Example,self).__init__()        self.initUI()    def initUI(self):                       textEdit = QTextEdit()        self.setCentralWidget(textEdit)        exitAction = QAction(QIcon('exit24.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.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_())
原创粉丝点击