【发布时间】:2020-10-08 17:06:54
【问题描述】:
我正在尝试使用 pygame 显示文本 代码如下:
pygame.font.init()
myFont = pygame.font.get_default_font()
text1 = "Welcome to tetris"
text = myFont.render(text1, True, (255,255,255))
screen.blit(text, (250, 350))
pygame.display.update()
但它唯一输出的是:
Traceback (most recent call last):
File "tetris.py", line 17, in <module>
text = myFont.render(text1, True, (255,255,255))
AttributeError: 'str' object has no attribute 'render'
我做错了什么?
【问题讨论】:
-
我猜
get_default_font返回的是字体的名称,而不是实际的字体对象。
标签: python pygame python-3.7