[PyQt5] 菜单栏、工具栏、状态栏

[PyQt5] 菜单栏、工具栏、状态栏_第1张图片

import sys

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction


class MainApp(QMainWindow):
    def __init__(self):
        super(MainApp, self).__init__()
        self.init_ui()

    def init_ui(self):
        self.setWindowTitle('我的窗口')
        self.setWindowIcon(QIcon('img/app.png'))

        new_action = QAction(QIcon('img/new.png'), '&新建...', self)
        new_action.setShortcut('Ctrl+N')
        new_action.setStatusTip('新建')

        exit_action = QAction(QIcon('img/exit.png'), '&退出', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.setStatusTip('退出应用程序')
        exit_action.triggered.connect(self.close)

        # 菜单栏
        menu_bar = self.menuBar()

        file_menu = menu_bar.addMenu('&文件')
        file_menu.addAction(new_action)
        file_menu.addAction(exit_action)

        edit_menu = menu_bar.addMenu('&编辑')

        # 工具栏
        self.toolbar = self.addToolBar('退出')
        self.toolbar.addAction(exit_action)

        # 状态栏
        self.statusBar()

        self.resize(800, 500)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_app = MainApp()
    sys.exit(app.exec_())

你可能感兴趣的:(PyQt5,pyqt5)