【问题标题】:TypeError: 'pygame.Surface' object is not callableTypeError:“pygame.Surface”对象不可调用
【发布时间】:2012-04-26 00:37:57
【问题描述】:

当我想进入游戏结束屏幕时,我遇到了这个问题。

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

谢谢

【问题讨论】:

    标签: python pygame


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-08-15
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      相关资源
      最近更新 更多