【问题标题】:How to display an utf-8 character in pygame?如何在pygame中显示一个utf-8字符?
【发布时间】:2020-07-19 09:48:04
【问题描述】:

有没有办法使用 pygame 渲染刻度线?我尝试像这样直接使用 unicode:

def write(screen, text, color, position, size):
    font = pygame.font.Font(pygame.font.get_default_font(), size)# Defining a font with font and size
    text_surface = font.render(text, True, color)# Defining the text color which will be rendered
    screen.blit(text_surface, (position[0], position[1])) # Rendering the font

write(window, u'\u2713', self.color, position, size) 

但这只是画了一个矩形。

【问题讨论】:

    标签: python pygame text-rendering


    【解决方案1】:

    这个正在写入的“矩形”实际上是使用pygame.font.get_default_font() 表示的 符号。为了显示 符号,您需要确保该符号包含在您正在使用的字体中。我提出以下解决方案:

    1. 下载包含此符号的字体(例如 here 的 Segoe UI Symbols)
    2. 将字体包解压到数据文件夹(或主应用文件夹)
    3. 将您正在使用的字体更改为下载的字体
        font = pygame.font.Font("seguisym.ttf", size)
    
    1. 通过write(window, u'\u2713', self.color, position, size) 方法或直接使用write(screen, "✓", self.color, position, size) 使用写入函数

    【讨论】:

      猜你喜欢
      • 2011-06-14
      • 2013-04-09
      • 1970-01-01
      • 2011-06-15
      • 2020-04-22
      • 1970-01-01
      相关资源
      最近更新 更多