I'm currently struggling with formatting the count up timer for my code. I want a regular timer that counts up in milliseconds, however, I can't figure out how to visually show this on the timer. At the moment it only shows milliseconds as opposed to minutes, seconds and milliseconds, so once the timer hits 100 milliseconds it simply keeps counting this way instead of 1 second 0 milliseconds. How can I get this to work?
import pygame
pygame.init()
screen = pygame.display.set_mode((450, 600))
timer_font = pygame.font.SysFont("Calibri", 38)
timer_sec = 0
timer_text = timer_font.render("00:00:00", True, (255, 255, 255))
timer = pygame.USEREVENT + 0
pygame.time.set_timer(timer, 10)
running = True
while running:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == timer:
if timer_sec < 600:
timer_sec += 1
timer_text = timer_font.render("00:00:%02i" % timer_sec, True, (255, 255, 255))
else:
pygame.time.set_timer(timer, 0)
screen.blit(timer_text, (300, 20))
pygame.display.update()