I'm making a stopwatch using Python and pyqt5 and I'm asking you a question because there's one problem.
(Set to 5 seconds for now) When I press the start button on the stopwatch, I want to make a code that runs 0 -> 1 -> 2 -> 3 -> 4 -> 5 in sequence on the GUI screen, but the code I squeeze is outputting 0 and a few seconds later to 5. Do you happen to have this error because there is a problem with thread? Or is there any other problem?
from PyQt5 import uic
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import datetime
import time
CalUI = '../poor_timer/timer_gui.ui'
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self, None)
uic.loadUi(CalUI, self)
self.timer = QTimer(self)
self.timer.timeout.connect(self.timeout)
self.lcdNumber.setDigitCount(8)
# 처음 값 세팅은 45분 15분 쉬기
self.lcdNumber.display('0')
# 알람끄기/ 공부 시작/ 공부 멈춤
self.pushButton.clicked.connect(self.onStartButtonClicked)
def onStartButtonClicked(self):
self.timer.start()
def timeout(self):
sender = self.sender()
for i in range(5):
currentTime = str(i)
self.lcdNumber.display(currentTime)
time.sleep(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
main_dialog = MainWindow()
main_dialog.show()
app.exec_()