我使用的是pygame,我使用的是一个在PyGame中设置文本选定位置的函数:
def textPos(YPos , TextSize):
TextPosition.center(60,YPos)
print("Size : " + TextSize)但是当我运行这个程序时,我得到一个错误:
TextPosition.center(60,YPos) : TypeError : 'Tuple' object is not callable 有办法解决这个问题吗?
发布于 2020-05-13 20:51:19
‘'Tuple’对象是不可调用的错误意味着你把一个数据结构当作一个函数,并试图在它上面运行一个方法。TextPosition.center是一个元组数据结构,而不是一个函数,您将它作为一个方法来调用。如果您尝试访问TextPosition.Center中的元素,请使用方括号[]
例如:
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
复制相似问题