【问题标题】:Font Rendering Error in PythonPython中的字体渲染错误
【发布时间】:2014-08-06 22:30:35
【问题描述】:

我目前正在使用 python 3.2.3 和 pygame 为我的游戏渲染字体。我目前收到错误:

Traceback (most recent call last):
  File "E:\FinalProject.py", line 249, in <module>
    drawLevel1(screen, guy)
  File "E:\FinalProject.py", line 107, in drawLevel1
    text = font.render("Level : %s" % (lvlNum), 1, (0,0,0))
AttributeError: 'module' object has no attribute 'render'

使用以下代码:

pygame.font.init()
pygame.font.SysFont("Grobold", 20)
if lvlNum == level1 or lvlNum == level2 or lvlNum == level3:
    text = font.render("Level : %s" % (lvlNum), 1, (0,0,0))

我不知道为什么会出现这个错误。对此错误的任何帮助表示赞赏。

【问题讨论】:

    标签: python fonts pygame render


    【解决方案1】:

    您可能不想使用pygame.font.SysFont("Grobold", 20):

    pygame.font.init()
    font = pygame.font.SysFont("Grobold", 20) #Assign it to a variable font
    text = font.render("Hello", 1, (0,0,0)) #Call render from the font variable
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-28
      • 2013-12-21
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 2014-09-02
      • 1970-01-01
      相关资源
      最近更新 更多