Ale865
Ale865

Reputation: 126

'Tuple' object is not callable - Python

I'm using pygame and I'm using a function that set the selected position of a text in PyGame :

def textPos(YPos , TextSize):
    TextPosition.center(60,YPos)
    print("Size : " + TextSize)

but when I run the program, I get an error:

TextPosition.center(60,YPos) : TypeError : 'Tuple' object is not callable 

There's a way to solve this problem?

Upvotes: 0

Views: 2359

Answers (1)

jetColormap
jetColormap

Reputation: 26

'Tuple' object is not callable error means you are treating a data structure as a function and trying to run a method on it. TextPosition.center is a tuple data structure not a function and you are calling it as a method. If you are trying to access an element in TextPosition.Center, use square brackets []

For example:

foo = [1, 2, 3]
bar = (4, 5, 6)

# trying to access the third element with the wrong syntax
foo(2) --> 'List' object is not callable
bar(2) --> 'Tuple' object is not callable

# what I really needed was
foo[2]
bar[2]

Upvotes: 1

Related Questions