메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

Pyqt 타이머: 두 판 사이의 차이

데브카페
새 문서: <source lang=python> import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import QTimer, QTime class MyWindow(QWidget): def __init__(self): super().__init__() self.timer = QTimer(self) self.timer.setInterval(0.5) self.timer.timeout.connect(self.timeout) self.setWindowTitle('QTimer') self.setGeometry(100, 100, 600, 280) layout = QVBoxLayout() self.lcd = QLCDNumber() self.lcd.display('')...
 
잔글 개발노트 양식 일괄 적용
 
1번째 줄: 1번째 줄:
{{개발노트
|요약=
|핵심=
|분야=Python
|작성일=2024-10-04
}}
<source lang=python>
<source lang=python>
import sys
import sys

2026년 11월 12일 (목) 12:44 기준 최신판

DEVCAFE NOTE
Python
KEY POINTS · 핵심 정리
작성일2024년 10월 4일
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QTimer, QTime
class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.timer = QTimer(self)
        self.timer.setInterval(0.5)
        self.timer.timeout.connect(self.timeout)
        self.setWindowTitle('QTimer')
        self.setGeometry(100, 100, 600, 280)
 
        layout = QVBoxLayout()
 
        self.lcd = QLCDNumber()
        self.lcd.display('')
        self.lcd.setDigitCount(15)
        subLayout = QHBoxLayout()
        
        self.btnStart = QPushButton("시작")
        self.btnStart.clicked.connect(self.onStartButtonClicked)
 
        self.btnStop = QPushButton("멈춤")
        self.btnStop.clicked.connect(self.onStopButtonClicked)
 
        layout.addWidget(self.lcd)
        
        subLayout.addWidget(self.btnStart)
        subLayout.addWidget(self.btnStop)
        layout.addLayout(subLayout)
 
        self.btnStop.setEnabled(False)
        self.setLayout(layout)        
    def onStartButtonClicked(self):
        self.timer.start()
        self.btnStop.setEnabled(True)
        self.btnStart.setEnabled(False)
    def onStopButtonClicked(self):
        self.timer.stop()
        self.btnStop.setEnabled(False)
        self.btnStart.setEnabled(True)
    def timeout(self):
        sender = self.sender()
        currentTime = QTime.currentTime().toString("hh:mm:ss,zzz")
        if id(sender) == id(self.timer):
            self.lcd.display(currentTime)
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = MyWindow()
    myWindow.show()
    sys.exit(app.exec_())