问题描述
我正在使用 pygame 并且我正在使用一个函数来设置文本的选定位置在 PyGame 中:
I'm using pygame and I'm using a function that set the selected position of a textin 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?
推荐答案
'Tuple' object is not callable 错误意味着您将数据结构视为函数并尝试在其上运行方法.TextPosition.center
是元组数据结构而不是函数,您将其作为方法调用.如果您尝试访问 TextPosition.Center
中的元素,请使用方括号 []
'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 []
例如:
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]
这篇关于“元组"对象不可调用 - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!