I have been helped to make a timer where if I press the space key, it restarts. I would like to edit this code so when I press the return/enter button, it pauses the timer, regardless of where the timer is (restarted, at 0, or in the middle). Of course, I don't want it to affect the rest of the code. Here is my code:
from turtle import Screen, Turtle, bgcolor
bgcolor('dodgerblue')
FONT = ("Arial", 60, "normal")
strings = input("Please enter the time: ").strip().split(' ')
time = [60 ** (len(strings) - index - 1) * int(unit) for index, unit in enumerate(strings)]
seconds = -1
ticking = False
def delSec(string):
if len(string)==1:
return "0"+string
else:
return string
def tick():
global seconds, ticking
turtle.clear()
if seconds < 0:
turtle.write("TIMER DONE", align='center', font=FONT)
ticking = False
else:
turtle.write(delSec(str(seconds//3600))+":"+delSec(str((seconds%3600)//60))+":"+delSec(str((seconds%60)//1)), align='center', font=FONT)
seconds -= 1
screen.ontimer(tick, 1000)
key = "space"
def reset():
global seconds, ticking, key
screen.onkey(None, key) # Disable event handler inside handler
seconds = sum(time)
if not ticking:
ticking = True
tick()
screen.onkey(reset, key) # Reenable event handler
screen = Screen()
turtle = Turtle()
turtle.hideturtle()
turtle.color('white')
reset()
screen.listen()
screen.mainloop()
I would appreciate any help, thanks in advance!
EDIT: I want it so that if the timer is paused, I can still reset it.