QUIT pygame event is not defined

Question:

I have two for loops:

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()

Whenever I run my code, I get this error:

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

I don’t know why it does this, because before it worked perfectly.

Asked By: Brady W

||

Answers:

Change if event.type == QUIT: to if event.type == pygame.QUIT:

Answered By: John

either do from pygame.locals import * or change if event.type == QUIT to if event.type == pygame.QUIT

Answered By: Reycko
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.