image comes after closing window?

628 views Asked by At
screen = pygame.display.set_mode([800,600])

pygame.display.set_caption("example")

background = pygame.Surface(screen.get_size())

background.fill(white)

clock = pygame.time.Clock()

background_image = pygame.image.load("example.jpg").convert()

background_position=[30,30]


done = False

while done == False:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done= True

screen.blit(background_image,background_position)

pygame.display.flip()

pygame.quit()

So I've been trying to load an image in pygame, probably very simple , I kinda got it to work but the image doesn't actually appear on the main surface it only appears for 2 seconds when I close the window. Did I forget to blit or update somewhere ? THANKS!

1

There are 1 answers

0
joaquin On

Try moving some lines inside the while loop:

while done == False:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done= True

    screen.blit(background_image,background_position)

    pygame.display.flip()

your image was not draw because your program was busy in the while loop, never reaching the actual drawing instructions. When you exit it with quit, then the three last lines were executed showing you your picture (for a moment).