[英]Font Rendering Error in Python
I am currently working on rendering a font for my game in python 3.2.3 and pygame. 我目前正在为python 3.2.3和pygame渲染游戏字体。 I am currently getting the error:
我目前收到错误消息:
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'
with the following code: 使用以下代码:
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))
I do not know why this error is occurring. 我不知道为什么会发生此错误。 Any help with this error is appreciated.
感谢您提供有关此错误的任何帮助。
In stead of using pygame.font.SysFont("Grobold", 20)
you probably want to do: 代替使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.