EDITED after answering too quickly
move your loop around:
while running:
rect = pygame.Rect(10, 20, 30, 30)
pygame.draw.rect(screen, (255,0,0), rect)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pressed = True
if event.type == pygame.QUIT:
running = False
while mouse_pressed:
# do your stuff
mouse_pressed = False
In your version, the whole loop never starts, since mouse_pressed
is initialized to False.