본문 바로가기
Python Library/PyQt

[PyQt] 툴바

by goatlab 2022. 5. 20.
728x90
반응형
SMALL

툴바

 

메뉴가 어플리케이션에서 사용되는 모든 명령의 모음이라면, 툴바 (toolbar)는 자주 사용하는 명령들을 더 편리하게 사용할 수 있도록 해준다.

 

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

class MyApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        exitAction = QAction(QIcon('exit.png'), 'Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(qApp.quit)

        self.statusBar()
        
        # 툴바에 exitAction 동작 추가
        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAction)

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

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())

728x90
반응형
LIST

'Python Library > PyQt' 카테고리의 다른 글

[PyQt] Error: Application failed to start because no Qt platform plugin could be initialized  (0) 2022.05.23
[PyQt] 메뉴바  (0) 2022.05.20
[PyQt] 상태바  (0) 2022.05.20
[PyQt] 툴팁  (0) 2022.05.20
[PyQt] 창 닫기 버튼  (0) 2022.05.20