【问题标题】:Trying to display text in python尝试在python中显示文本
【发布时间】: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'

我做错了什么?

【问题讨论】:

标签: python pygame python-3.7


【解决方案1】:

没关系,我自己解决了这个问题。 get_default_font() 函数只返回字体的名称。我只是使用默认字体的文件名并创建了一个字体对象。

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2019-05-12
    相关资源
    最近更新 更多