rafitufi
rafitufi

Reputation: 25

Python pygame event loop type error

I am making a simple pygame game. My problem is, when I try to check if the user is clicking the exit button, I get an error. Here's the Code:

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

Here's the error:

Traceback (most recent call last):
File "C:\Users\Rafi\Python Programs\Game.py", line 20, in <module>
if event.type == pygame.QUIT():
TypeError: 'int' object is not callable

Also, this probably doesn't but i'm on Windows 8.

Upvotes: 2

Views: 929

Answers (2)

pradyunsg
pradyunsg

Reputation: 19416

>>> pygame.QUIT
12

So,

>>> pygame.QUIT() >> 12()
TypeError: 'int' object is not callable

IN text, pygame.QUIT = 12 so doing pygame.QUIT() is equivalent of doing 12(), which is a call, which is not what you want.

Just change your line to:

if event.type == pygame.QUIT:

Upvotes: 2

ThisIsAQuestion
ThisIsAQuestion

Reputation: 1967

pygame.QUIT is a constant (12 in case you were wondering). It doesn't require any () after it. That's all your problem is.

Upvotes: 0

Related Questions