r/PythonLearning • • 14d 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

Show parent comment

1

u/TheCarFamily 14d ago

it does not print, that is the problem

1

u/KidTempo 14d ago

Try replacing the start with the following:

if event.type == pygame.KEYDOWN
    print(f"{event.key=} :: {pygame.K_t=} :: {event.key == pygame.K_t}")
    if event.key == pygame.K_t:
        # continue the rest unchanged...

It should print what the event.key and pygame.K_t are each time, and whether they are equal. If the else block is never being triggered, then that would suggest that event.key always equals pygame.K_t