본문 바로가기

프로그래밍 관련/PyQt31

PyQt(4) 쓰레드 사용하기 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from PyQt5.QtCore import QThread import time class MyThread(QThread): cnt=0 def __init__(self): super().__init__() def run(self): while True: self.cnt=self.cnt+1 print("running %d" %self.cnt) time.sleep(1) class MyWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Test") self.setGeometry(1000, 200,.. 2021. 9. 14.
PyQt(3) 버튼 이벤트 만들기 GUI 프로그램이라면 일반적으로 유저가 어떤 버튼을 누르면 어떤 동작을 하는 식으로 동작할 것이다. import sys from PyQt5.QtWidgets import * class MyWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Test") self.setGeometry(1000, 200, 300, 300) btn1 = QPushButton("테스트 버튼1", self) btn1.move(30, 120) btn1.clicked.connect(self.btn_fun1) def btn_fun1(self): print("button is clicked") if __name__ == "__main__": ap.. 2021. 9. 13.
PyQt(2) 타이머 인터럽트 만들기 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import QTimer class MyWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Test") self.setGeometry(1000, 200, 300, 300) # timer 1 self.timer = QTimer(self) self.timer.start(100) self.timer.timeout.connect(self.timeout_fun) self.time_cnt =0 # timer 2 self.timer2 = QTimer(self) self.timer2.start(500) self.timer2.. 2021. 9. 13.
PyQt(1) 쌩기초 샘플 코드 0.PyQt 설치하기 cmd 창에서 pip install pyqt5 2021. 9. 13.