QUIT pygame事件未定义

时间:2015-05-12 19:15:09

标签: python events pygame

我有两个for循环:

for event in pygame.event.get():
        if event.type == QUIT:
                        pygame.quit()
                        quit()
        if event.type == KEYDOWN:
                if event.key == K_p:
                        banana = False
                        sportscar = True

for event in pygame.event.get:
                if event.type == QUIT:
                        pygame.quit()
                        quit()

每当我运行我的代码时,都会收到此错误:

Traceback (most recent call last):
  File "D:\Calorie Calculator v2.py", line 43, in <module>
    if event.type == QUIT:
NameError: name 'QUIT' is not defined

我不知道为什么会这样做,因为在它完美运作之前。

1 个答案:

答案 0 :(得分:3)

if event.type == QUIT:更改为event.type == pygame.QUIT: