반응형
    
    
    
  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.timeout.connect(self.timeout_fun2)
        self.time_cnt2 =0
    
    def timeout_fun(self):
       self.time_cnt += 1
       print("time cnt is %d" %self.time_cnt)
    def timeout_fun2(self):
       self.time_cnt2 += 1
       print("time cnt2 is %d" %self.time_cnt2)   
    
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = MyWindow()
    myWindow.show()
    app.exec_()
코드 보면 내용 이해 가리라 믿는다 .별도의 설명은 생략한다.
참고로 타이머 클래스의 start 함수 안에 들어가는 숫자의 단위는 ms이다.
이 코드를 실행하면 gui 창이 실행된 상태로,
timeout_fun 함수는 100ms 마다 실행 될 것이고
timeout_fun2 함수는 500ms마다 실 될 것이다.
반응형
    
    
    
  '프로그래밍 관련 > PyQt' 카테고리의 다른 글
| PyQt. Qt Designer 개요.사용방법 (1) | 2021.10.19 | 
|---|---|
| PyQt() Keyboard 이벤트, Keyboard인터럽트 pynput 라이브러리 (1) | 2021.09.16 | 
| PyQt(4) 쓰레드 사용하기 (0) | 2021.09.14 | 
| PyQt(3) 버튼 이벤트 만들기 (0) | 2021.09.13 | 
| PyQt(1) 쌩기초 샘플 코드 (0) | 2021.09.13 |