问题
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?
回答1:
'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]
来源:https://stackoverflow.com/questions/61775032/tuple-object-is-not-callable-python