2

So I've tried to create a window with a white background and a blue rectangle. After I run module, the window successfully popped up, and my debugging message indicating completion of main was also printed to the counsel. However, my background is still black and the rectangle did not show up at all. Any suggestions on why this is happening? Thanks!

pygame.init()
running = True

screen = pygame.display.set_mode((640,480))

WHITE=(255,255,255)
BLUE=(0,0,255)

def main():

    screen.fill(WHITE)    

    my_rect = pygame.Surface( (100,100) )
    my_rect.fill(BLUE)

    screen.blit(my_rect, [50, 50])

    pygame.draw.rect(screen,WHITE,(200,150,100,50)) # Second attempy to draw a 
                                                    # rectangle
    print ("Main statements executed")              # My debugging line

Maggie Mao
  • 177
  • 1
  • 9

1 Answers1

2

You need to refresh the display, by calling the display.flip function.

Just add pygame.display.flip after blitting your rectangle, and you're good:

screen.blit()
pygame.display.flip()
Right leg
  • 16,080
  • 7
  • 48
  • 81