import pygame
import time
pygame.font.init()
WIDTH, HEIGHT = 1000, 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(“Timer”)
FONT = pygame.font.SysFont(“times new roman”, 50)
def draw(elapsed_time):
time_text = FONT.render(f”Time: {round(elapsed_time)}s”, 1, “white”)
WIN.blit(time_text, (400, 350))
pygame.display.update()
def main():
run = True
clock = pygame.time.Clock()
start_time = time.time()
elapsed_time = 0
while run:
elapsed_time = time.time() - start_time
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
draw(elapsed_time)
pygame.quit()
if name == “main“:
main()
I tried adding writing the elapsed_time under def main() with += so it can update, but still doesn’t work.
AugustusRomulus44 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.