简体   繁体   中英

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?

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.

而不是from pygame import * ,使用:

from pygame.locals import *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM