Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pygame event handling

Just a noob question about python and pygame event handling.

I got the following code in a pygame tutorial:

while 1:
   for event in pygame.event.get():
       if event.type in (QUIT, KEYDOWN):
            sys.exit()

...but for some reason it returns this error:

if event.type in (QUIT, KEYDOWN):
NameError: name 'QUIT' is not defined

Can anyone explain this?

like image 699
Aresfd Avatar asked Apr 07 '26 17:04

Aresfd


1 Answers

I think you meant this:

if event.type in (pygame.QUIT, pygame.KEYDOWN)

The tutorial probably used from pygame import *, and this example perfectly shows why this is a bad habit.

like image 156
orlp Avatar answered Apr 09 '26 06:04

orlp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!