Reputation: 187
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
Upvotes: 2
Views: 160
Reputation: 16720
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()
Upvotes: 2