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):
开发者_Python百科 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?
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.
instead of from pygame import *
, use:
from pygame.locals import *
精彩评论