728x90
728x90
QTimer.singleShot 함수를 특정 시간 간격으로 여러번 실행하는 방법
들어가며
PyQt5
에서QTimer.singleShot
함수를 특정 시간 간격으로 여러번 실행할 수 있다.QTimer.singleShot
함수는 밀리초 단위의 시간 지연을 준 후, 특정 함수를 실행해주는 함수이다.

예제
- 다음은
QTimer.singleShot
함수를 3초 간격으로 여러 번 실행하는 예제이다. - 반복문과 재귀 호출을 이용하여 구현하였다.
from PyQt5.QtCore import QTimer class MyClass: def __init__(self): self.count = 0 def start_timer(self): self.count = 0 self.run_timer() def run_timer(self): if self.count < 5: # 원하는 실행 횟수 설정 QTimer.singleShot(3000, self.run_timer) self.count += 1 print("Timer executed:", self.count) else: print("Timer execution finished") # MyClass 인스턴스 생성 obj = MyClass() # 타이머 실행 obj.start_timer()
Timer executed: 1 Timer executed: 2 Timer executed: 3 Timer executed: 4 Timer executed: 5 Timer execution finished
참고 사이트
QTimer Class | Qt Core 6.5.2
doc.qt.io
728x90
728x90
'Framework > PyQt' 카테고리의 다른 글
[PyQt] 플랫폼 독립적인(Platform Independent) 스타일 적용하는 방법 (Fusion) (0) | 2023.09.21 |
---|---|
[PyQt] 맥(Mac)에서 윈도우(Windows)와 비슷하게 메뉴 표시하는 방법 (0) | 2023.09.21 |
[PyQt] QTableWidget에 1,000 단위로 쉼표(,)를 추가하고 숫자 정렬 기능 추가하기 (0) | 2023.07.20 |
[PyQt] 간단한 CRUD(Create, Read, Update, Delete) 프로그램 (0) | 2023.07.18 |
[PyQt] QAction에서 triggered 시그널을 사용할 때, 인자를 triggered 메서드에 전달하는 방법 (0) | 2023.07.08 |
[PyQt] QClipboard.Clipboard와 QClipboard.Selection의 차이점 (0) | 2023.07.07 |
[PyQt] 커스텀 아이콘 패키지(fugueicons) 설치 및 사용해보기 (0) | 2023.07.05 |
[PyQt] style().standardIcon() 메서드에서 사용할 수 있는 아이콘 종류 및 숫자 (1) | 2023.05.17 |