how are you, I am writing to ask you how I can do it, currently I have a clock with a countdown (10 minutes) in the main window, on the other screen (toplevel) I have another clock with a countdown but of 24 seconds, everything is perfect but The only thing that I cannot solve is: how to make it so that when I press the button (reset 24 seconds) it goes back to 24 and that everything continues to work normally, since what it does is for a moment it puts me at 24 seconds and then it returns where was the countdown at the time of pressing the reset button.
def countdown(self,minutos,segundos,posesion):
if self.is_running:
minutos_final=int(minutos)
segundos_final=int(segundos)
posesion_final=int(posesion)
self.text_minutos.set(f"{minutos_final:02d}")
self.text_segundos.set(f"{segundos_final:02d}")
self.text_segundos_posesion.set(posesion_final)
if segundos_final > 0:
self.after_id =self.tablero_principal.after(1000,self.countdown,minutos_final,segundos_final -1,posesion_final-1)
if segundos_final ==0 and minutos_final>0:
segundos_final=60
self.after_id =self.tablero_principal.after(1000, self.countdown,minutos_final-1, segundos_final-1,posesion_final-1)
def iniciar(self):
if not self.is_running: ## avoid 2 button pushes
self.is_running=True
if self.text_segundos_posesion.get()=="0":
self.countdown(self.text_minutos.get(),self.text_segundos.get(),24)
elif self.text_minutos.get()=="00" and self.text_segundos.get()=="00":
self.countdown(self.text_minutos_fijos,self.text_segundos_fijos,24)
self.text_cuarto.set(str(int(self.text_cuarto.get()) + 1))
else:
self.countdown(self.text_minutos.get(),self.text_segundos.get(),self.text_segundos_posesion.get())
def parar(self):
self.is_running = False
self.tablero_principal.after_cancel(self.after_id)
def forzar_24(self): #HERE IS THE PROBLEM
self.tablero_principal.after_cancel(self.after_id)
self.text_segundos_posesion.set("24")
self.iniciar()