2014-04-18 78 views
0

我想在左上角顯示帶有可更新分數的字體。但它顯示了一個錯誤:Python/Pygame TypeError:'str'對象無法調用

Traceback (most recent call last): File "C:\Users\Mäse\workspace\Snake\src\snake_game__init__.py", line 24, in score_display = font.render("Score: %d"(score), 1, BLACK) TypeError: 'str' object is not callable

這裏是我的代碼:

> font = pygame.font.Font(None, 16) 
> score = 0 
> score_display = font.render("Score: %d"(score), 1, BLACK 

這並不是全部的代碼,你需要的部分。我知道如何將文本複製,當我這樣做時我就會遇到錯誤。

回答

4
"Score: %d"(score) 

應該

"Score: %d" % score 

或者,更好:

"Score: {0}".format(score)