pygame事件处理

Are*_*sfd 2 python pygame event-handling

只是关于python和pygame事件处理的noob问题.

我在pygame教程中得到以下代码:

while 1:
   for event in pygame.event.get():
       if event.type in (QUIT, KEYDOWN):
            sys.exit()
Run Code Online (Sandbox Code Playgroud)

...但由于某种原因,它会返回此错误:

if event.type in (QUIT, KEYDOWN):
NameError: name 'QUIT' is not defined
Run Code Online (Sandbox Code Playgroud)

有谁能解释一下?

orl*_*rlp 16

我想你的意思是:

if event.type in (pygame.QUIT, pygame.KEYDOWN)
Run Code Online (Sandbox Code Playgroud)

本教程可能会使用from pygame import *,这个例子很好地说明了为什么这是一个坏习惯.