아미(아름다운미소)

Python PyQt 이벤트 처리 본문

랭귀지/python

Python PyQt 이벤트 처리

유키공 2018. 9. 13. 09:30
GUI 프로그램은 기본적으로 사용자의 이벤트에 따라 동작합니다.  
예를 들어, 윈도우에는 'Click me'라는 버튼이 하나 있습니다. 
사용자가 해당 버튼을 마우스로 클릭하면 화면에 'clicked'라는 메시지 박스가 출력됩니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''
Created on 2018. 9. 10.
 
@author: bhm
'''
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
 
class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("PyStock")
        self.setGeometry(300, 300, 300, 400)
 
        btn1 = QPushButton("Click me", self)
        btn1.move(20, 20)
        btn1.clicked.connect(self.btn1_clicked)
 
    def btn1_clicked(self):
        QMessageBox.about(self, "message", "clicked")
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = MyWindow()
    myWindow.show()
    app.exec_()

PyQt



Comments