Ask coding questions

← Back to all posts
What’s wrong with Pygame?
jort57

I don’t know if it’s just me, but whenever I try to run pygame, it sort of freezes forever and I can’t run my project. Would someone please help?

Answered by DEMONul1234 [earned 5 cycles]
View Answer
Voters
jort57
Comments
hotnewtop
DEMONul1234

The problem is here:

def fill():
if keys[pygame.K_D]:
return
you have to place it after:
keys = pygame.key.get_pressed()

or python will tell you that "keys" has not been defined yet

jort57

@DEMONul1234 Thank you so much!

DEMONul1234

So think about this problem like this:
"Kevin, please bring me two apples"
"But I don't even know what apples are!"
Instead try:
"Son, apples are red fruits, if you see some, bring 'em to me"
"Ok, since I know what apples are, I'll bring them to you"