I have a simple GUI App, it's a timer with LCD display I have problem with delaying one function that's responsible for counting down the time it's should count down every second, but it's count the minute in one second, it for loop function here the demo of the project
from PySide2 import QtWidgets , QtCore
import sys
from clock_gui import Ui_clock # this is the GUI components
class clockApp(QtWidgets.QMainWindow, Ui_clock):
def __init__(self):
super(clockApp,self).__init__()
self.setupUi(self) # it set up the UI from Ui_clock
self.min = self.spinBox_min.value()
self.sec = self.spinBox_sec.value()
self.button.clicked.connect(self._buttonFunction) # the button
self.show() # render the GUI
def _buttonFunction(self): # the function that counts down after the button clicked
self.total = (self.min *60) + self.sec # take minutes and seconds to one variable
if self.total >=1:
for i in range(self.total):
self.total -= 1
# here the problem I want the delay to start here
# I can use time.sleep but I want to use Qtimer I try it in different ways, but didn't work there is no error but the Qtimer didn't delay anything
app = QtWidgets.QApplication(sys.argv)
window = clockApp()
app.exec_()
I try setInterval and I try singleShot but nothing works, maybe I use them wrong?