如何在pygame中显示一个utf-8字符?

用户12291970

有没有办法使用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) 

但这只是绘制了一个矩形。

本杰明

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章