类型错误:“pygame.Surface"对象不可调用 [英] TypeError: 'pygame.Surface' object is not callable
问题描述
当我想进入游戏结束屏幕时,我遇到了这个问题.
I have this issue when I would like to go the Game Over screen.
Traceback (most recent call last):
File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 215, in <module>
game()
File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 191, in game
text("Game Over",30,white,300)
TypeError: 'pygame.Surface' object is not callable
这是存在屏幕的代码部分:
This the section of the code for the exist screen:
while finish == True:
screen.blit(menu,[0,0])
text("Game Over",30,white,300)
text("Instructions",310,white)
text("-----------------------------------------------------",320,white)
text("Avoid the the enemies",340,white)
text("Last as long as you can!",360,white)
text("Press space to start",420,white)
# display.update()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
repeat = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
repeat = True
if repeat == False:
pygame.quit()
else:
game()
game()
如果我删除游戏画面中的文本,它确实有效.我一介绍文字,就会收到上述错误消息
If I remove the text within the game over screen, it does work. I as soon as I introduce text I get the above error message
(缩进不正确)我在这里有完整的 inden 代码 http://pastebin.com/VBkhX4kt
(indention is not correct) I have the full code with inden here http://pastebin.com/VBkhX4kt
谢谢
推荐答案
错误是因为在第 93 行,您覆盖了变量 text
从函数到 font.render() 返回的任何内容的绑定.
The error is because on line 93 you override the binding of the variable text
from a function to whatever font.render() returns.
93: text = font.render('Starting Twerk... ', True, (100,100,100))
因此,稍后,当您调用 text(...)
时,它不会调用您之前定义的函数,而是试图将 text
视为可调用的(它不是,因为它现在是一个 pygame.Surface 对象).
Thus, later on, when you call text(...)
it's not calling the function you defined earlier, it's trying to treat text
as a callable (which it is not, since it is now a pygame.Surface object).
解决方案是更改该行而不是覆盖您的 text
函数.
The solution would be to alter that line and not override your text
function.
这篇关于类型错误:“pygame.Surface"对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!