import pygame
import random
import time

pygame.init()
ekran = pygame.display.set_mode((800, 650))
zegar = pygame.time.Clock()

run = True
def flash_screen(color, duration, flashes, secondary):
   
    for _ in range(flashes):
        ekran.fill(color)
        pygame.display.flip()
        time.sleep(duration)
        ekran.fill(secondary)
        pygame.display.flip()
        time.sleep(duration)

while run:
    for e in pygame.event.get():
        if e.type == pygame.QUIT: run = False
        if e.type == pygame.KEYUP:
            if e.key == pygame.K_z:
                
                flash_screen((209, 21, 230),0.05,2,(128, 5, 121))
                ekran.fill((209, 21, 230))
            if e.type == pygame.KEYUP:
                    if e.key == pygame.K_x:
                        flash_screen((20, 229, 252),0.05,2,(17, 174, 191))
                        ekran.fill((20, 229, 252))
            if e.type == pygame.KEYUP:
                    if e.key == pygame.K_n:
                        flash_screen((9, 245, 5),0.05,2,(18, 143, 16))
                        ekran.fill((9, 245, 5))
            if e.type == pygame.KEYUP:
                    if e.key == pygame.K_m:
                        flash_screen((224, 9, 27),0.05,2,(18, 143, 16))
                        ekran.fill((224, 9, 27))
    pygame.display.flip()
    zegar.tick(60)
pygame.quit()