I'm trying to make a timer with pygame but I got stuck since I don't know how to make it work by pressing the "start" button (line 29 ). Here's my code:
I wanted to post my whole code but it's gonna be too long and the website just doesn't allow it to be like that.
The above are variables, some drawings, colors, text, and some steps to create a window in pygame.
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if (70 < mouse_x < 130) and (70 < mouse_y < 130):
mins = mins + 1
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)
if (170 < mouse_x < 230) and (70 < mouse_y < 130):
mins = mins - 1
if mins < 0:
mins = 0
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)
if (70 < mouse_x < 130) and (220 < mouse_y < 280):
secs = secs + 1
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)
if (170 < mouse_x < 230) and (220 < mouse_y < 280):
secs = secs - 1
if secs < 0 and mins == 0:
secs = 0
if secs < 0 and mins > 0:
secs = 59
mins = mins - 1
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)
if (290 < mouse_x < 435) and (70 < mouse_y < 130):
mouse_press_time = pygame.time.get_ticks()
if current_time - mouse_press_time == 1000:
secs = secs - 1
if secs < 0 and mins == 0:
secs = 0
if secs < 0 and mins > 0:
secs = 59
mins = mins - 1
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)
print(f"current time: {current_time}; mouse press time: {mouse_press_time}")
pygame.display.flip()
pygame.quit()