행위

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

DB CAFE

(새 문서: <source lang=python> import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import QTimer, QTime class MyWindow(QWidget): def __init__(self): super().__init__()...)
 
7번째 줄: 7번째 줄:
 
         super().__init__()
 
         super().__init__()
 
         self.timer = QTimer(self)
 
         self.timer = QTimer(self)
         self.timer.setInterval(1000)
+
         self.timer.setInterval(0.5)
 
         self.timer.timeout.connect(self.timeout)
 
         self.timer.timeout.connect(self.timeout)
 
         self.setWindowTitle('QTimer')
 
         self.setWindowTitle('QTimer')
16번째 줄: 16번째 줄:
 
         self.lcd = QLCDNumber()
 
         self.lcd = QLCDNumber()
 
         self.lcd.display('')
 
         self.lcd.display('')
         self.lcd.setDigitCount(8)
+
         self.lcd.setDigitCount(15)
 
         subLayout = QHBoxLayout()
 
         subLayout = QHBoxLayout()
 
          
 
          
43번째 줄: 43번째 줄:
 
     def timeout(self):
 
     def timeout(self):
 
         sender = self.sender()
 
         sender = self.sender()
         currentTime = QTime.currentTime().toString("hh:mm:ss")
+
         currentTime = QTime.currentTime().toString("hh:mm:ss,zzz")
 
         if id(sender) == id(self.timer):
 
         if id(sender) == id(self.timer):
 
             self.lcd.display(currentTime)
 
             self.lcd.display(currentTime)

2020년 9월 28일 (월) 11:56 판

thumb_up 추천메뉴 바로가기


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_())