繁体   English   中英

TypeError:“ pygame.Surface”对象不可调用

[英]TypeError: 'pygame.Surface' object is not callable

我想进入游戏结束屏幕时遇到此问题。

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

存在屏幕的代码部分:

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()

如果我在屏幕上方的游戏中删除了文本,那么它确实可以工作。 我一经介绍文字,就会收到上述错误消息

(缩进不正确)我在这里有inden的完整代码http://pastebin.com/VBkhX4kt

谢谢

该错误是因为在第93行上,您覆盖了将变量text从函数绑定到font.render()返回的内容的绑定。

93: text = font.render('Starting Twerk... ', True, (100,100,100))

因此,稍后,当您调用text(...)它没有调用您先前定义的函数,而是试图将text视为可调用的(不是,因为现在是pygame.Surface对象)。

解决方案是更改该行而不覆盖您的text函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM