1

The code is meant to quickly exit pygame by tapping escape.

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN():
            if event.key == pygame.K_ESCAPE:
                running = False
                pygame.quit()
                sys.exit()

This code errors with this:

Message File Name   Line    Position    
Traceback               
    <module>    G:\Code\JonSocket\keyboard.py   19      
TypeError: 'int' object is not callable             

Very similar code works when,

event.type == pygame.QUIT

Is there a difference between pygame.QUIT + pygame.KEYDOWN?

Thanks.

4
  • 1
    Minimal reproduction case: x = 1; x(). Make sure to listen to the error messages - this is too localized and very duplicated. Commented Nov 8, 2014 at 21:20
  • Thank-you for the answers. I got it solved, like the comments say, Change it to if event.type == pygame.KEYDOWN: Commented Nov 8, 2014 at 21:21
  • pygame.quit is a function but pygame.QUIT is an int. You can verify this with print(type(pygame.QUIT)) Commented Nov 8, 2014 at 21:28
  • "Very similar code works" - no it doesn't. pygame.QUIT() throws the same error. pygame.QUIT is an integer (12 to be exact). pygame.quit() is a function. Python is case sensitive. Commented Nov 8, 2014 at 21:31

1 Answer 1

5

Your problem is in the line

if event.type == pygame.KEYDOWN():

pygame.KEYDOWN is not a function but just an integer constant.

Change it to

if event.type == pygame.KEYDOWN:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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