import pygame from pygame.locals import * import sys BLACK = (0,0,0) RED = (255,0,0) GREEN = (0,255,0) BLUE = (0,0,255) WHITE = (255,255,255) pygame.init() current_time = 0 button_pressed_time = 0 screen = pygame.display.set_mode((800, 800)) clock = pygame.time.Clock() while True : for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() #Tracks when the button was last pressed and turns screen white if event.type == pygame.KEYDOWN: button_pressed_time = pygame.time.get_ticks() screen.fill(WHITE) current_time = pygame.time.get_ticks() # After 2 seconds have passed the screen fills black again if (current_time - button_pressed_time) > 1000: screen.fill(BLACK) print(f"Current time: {current_time} button press time: {button_pressed_time}") pygame.display.update() clock.tick(60)