trying to make a timer with resume/pause/reset/stop features. So in my previous question, someone recommended using pygame. so with my newbie experience tried to use pygame as best as I know. in another demo project, I was doing to learn python, keydown was successfully making things happen in the program. but here I tried using the same way and for some reason, the while loop is completely ignoring my keydown and continues looping. i even tried moving the keydown code into the while loop, but still no use. need help. What's wrong and how do I make what I want happen?
below in the link image is the output as its coming. as you can see its clearly ignoring my keydown commands and the W's I pressed during the while loop are entering at the end.
import time
import datetime
import pygame
pygame.init()
timeron = True
while timeron:
def timeinput():
h = input("Enter the time in hours: ")
m = input("Enter the time in minutes: ")
s = input("Enter the time in seconds: ")
countdown(int(h), int(m), int(s))
def countdown(h, m, s):
print("Press w to reset \nPress s to stop \nPress a to pause \nPress d to resume")
total_seconds = h * 3600 + m * 60 + s
while total_seconds > 0:
timer = datetime.timedelta(seconds=total_seconds)
print(timer, end='\r')
time.sleep(1)
total_seconds -= 1
print("Bzzzt! The countdown is at zero seconds!")
timeinput()
for event in pygame.event.get():
if event.type == pygame.QUIT:
timeron = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
total_seconds = 0
print("Timer will reset")
timeinput()
pygame.quit()