r/PythonLearning • • 22d ago

Help Request Else statement not working

Post image

Hello, my else statement is not working- the if statement its inside is, did i mess up the indents again or is it something else?

also would a display flip work to change the image back to the other image in the else statement?
any help is nice!

26 Upvotes

12 comments sorted by

View all comments

1

u/p1geondove 22d ago

it is indented one to far, but python can handle this luckily. about if display.flip() stores the last buffer: hmm maybe, why dont you try out? :)

import pygame
window = pygame.display.set_mode((500,500))
img = pygame.image.load("ragebait.png")

window.fill("grey10")
window.blit(img)
pygame.display.flip()

window.fill("grey10")
window.blit(img,(100,100))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            pygame.display.flip()
        elif event.type == pygame.QUIT:
            exit()

https://github.com/pygame-community/pygame-ce/blob/main/src_c/display.c

was curios to find out why, but i think flip is just a historical name. the way i read it, theres no actual double buffer involved, it only draws to the surface whats in screen->buffer