I have a task, where I have a square 3X3 and for every click in the small square, this square will paint in red. Here is my code yet. I think I did something wrong in my first while loop, but I'm not sure. Please help me.
import pygame pygame.init() #create a screen screen = pygame.display.set_mode((400, 400)) #colors white = [255, 255, 255] red = [255, 0, 0] x = 0 y = 0 #create my square for j in range(3): for i in range(3): pygame.draw.rect(screen, white, (x, y, 30, 30), 1) x += 30 if x == 90: x = 0 y += 30 pygame.display.flip() running = 1 while running: event = pygame.event.poll() #found in what position my mouse is if event.type == pygame.QUIT: running = 0 elif event.type == pygame.MOUSEMOTION: print("mouse at (%d, %d)" % event.pos) mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() #mouse click if click[0] == 1 and x in range(30) and y in range (30): pygame.draw.rect(screen, red, (30, 30 , 29 ,29)) while pygame.event.wait().type != pygame.QUIT: pygame.display.change() 