Python中的字体呈现错误

2024-03-28 08:44:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在为python3.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'

代码如下:

^{pr2}$

我不知道为什么会发生这个错误。如有任何帮助,我们将不胜感激。在


Tags: inpy游戏most错误line字体render
1条回答
网友
1楼 · 发布于 2024-03-28 08:44:23

代替使用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

相关问题 更多 >