Search code examples
python-3.xpygametypeerror

Pygame TypeError: 'int' object is not callable


This few lines of python 3.2 code uses the latest pygame module to move an image. It is related to this example: http://www.pygame.org/docs/tut/MoveIt.html

Here is my code:

import pygame
import sys 

pygame.init()
screen = pygame.display.set_mode((600,400))
bg = pygame.image.load('bg.jpg')
player = pygame.image.load('player.jpg')
pos = player.get_rect()

while True:
    for i in pygame.event.get():
       if i.type() == pygame.QUIT:
            sys.exit()
    screen.blit(bg,(0,0))
    screen.blit(player,(i,i))
    pygame.display.update()

Here is the error I get when running it:

Traceback (most recent call last):
File "C:/Users/Grounds Keeper Willy/Desktop/Python Code/test.py", line 12, in
if i.type() == pygame.QUIT:
TypeError: 'int' object is not callable

I have found similar questions but the answers stated that the problem was using a function name as a variable too, which is not what I'm doing. I cannot seem to figure out what is wrong here.


Solution

  • It should read:

    if i.type == pygame.QUIT:
    

    instead of:

    if i.type() == pygame.QUIT:
    

    since the type member of the Event class is not a function, so you don't need/can call it by using ().