2

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.

5
  • What error do you get? From the tags, I would guess it's a TypeError. Commented Apr 27, 2013 at 16:36
  • Yeah. Sorry, i'll edit in the error now. Commented Apr 27, 2013 at 16:37
  • You have to add all relevant code. What's going on around line 20, what's 'i'? Commented Apr 27, 2013 at 16:41
  • 1
    I am not familiar with pygame, but from the documentation, it looks like QUIT is a literal, not a method. If that's the case, doing QUIT() would cause this error. Here are some examples of other code using QUIT: nullege.com/codes/search?cq=pygame.event.get. Commented Apr 27, 2013 at 16:42
  • sorry, somehow made a typo, meant event where it says i. Commented Apr 27, 2013 at 16:43

2 Answers 2

2
>>> 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:
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.