开发者

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 *

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜