0swald 0swald - 1 year ago 192
Python Question

Pygame. TypeError: 'pygame.Surface' object is not callable

I am new to Python, Pygame, and just coding in general.

I do not know why my code is getting:

"TypeError: 'pygame.Surface' object is not callable"

and a black screen.

Here is my code:

import pygame
pTypeError: 'pygame.Surface' object is not callableygame.init

black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

char_sprite = pygame.image.load("man.png")

display_height = 800
display_width = 1000
dead = False
framerate = 60

game_display = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Tiny Fighter")
clock = pygame.time.Clock()

def char(x,y):

x= display_width / 2
y= display_height / 2

while not dead:
for event in pygame.event.get():
if event.type == pygame.QUIT:
dead = True




Full Traceback:

Traceback (most recent call last): File "/home/hayden/Desktop/Tiny
fighter/Tiny Fighter.py", line 35, in
char_sprite(x,y) TypeError: 'pygame.Surface' object is not callable

Answer Source

You have a typo. You spelled display wrong. Also, you misspelled the method name; should be char(x, y) not char_sprite(x, y).