아미(아름다운미소)

PyQt5 메뉴바(QAction 사용) 본문

랭귀지/python

PyQt5 메뉴바(QAction 사용)

유키공 2018. 11. 30. 11:30

PyQt5 , QAction 사용하여 menubar 만들기

#-*- coding: utf-8 -*-
'''
Created on 2018. 11. 29.

@author: bhm
'''
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon


class Example(QMainWindow):
    def __init__(self):
        super().__init__()

        exit_action = QAction(QIcon('exit.png'), "&Exit", self)
        # exit_action = QAction('&Exit', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.setStatusTip('Exit application')

        exit_action.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fielmenu = menubar.addMenu('&File')
        fielmenu.addAction(exit_action)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Menubar')
        self.show()


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


Comments