【问题标题】:Displaying unicode symbols using pygame使用 pygame 显示 unicode 符号
【发布时间】:2021-11-22 00:02:32
【问题描述】:

我检查了其他答案,但不明白为什么我的代码显示不正确 ♔。

This is what I currently see

这里是关于文本渲染的相关代码。

font = pygame.font.SysFont('Tahoma', 80, False, False)
queenblack = "♔"
queenblacktext = font.render(queenblack, True, BLACK)
screen.blit(queenblacktext, [80, 80])
pygame.display.flip()

感谢所有帮助我们,谢谢。我使用 python 3.8,并使用 Pycharm。

【问题讨论】:

    标签: python unicode pygame


    【解决方案1】:

    “Tahoma”字体不提供 unicode 字符。

    如果您的系统支持,请使用 "segoeuisymbol" 字体:

    seguisy80 = pygame.font.SysFont("segoeuisymbol", 80)
    

    注意,支持的字体可以通过print(pygame.font.get_fonts())打印。

    或者下载字体Segoe UI Symbol并创建一个pygame.font.Font

    seguisy80 = pygame.font.Font("seguisym.ttf", 80)
    

    使用字体渲染标志:

    queenblack = "♔"
    queenblacktext = seguisy80.render(queenblack, True, BLACK)
    

    小例子:

    import pygame
    
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    
    pygame.init()
    window = pygame.display.set_mode((500, 500))
    
    seguisy80 = pygame.font.SysFont("segoeuisymbol", 80)
    queenblack = "♔"
    queenblacktext = seguisy80.render(queenblack, True, BLACK)
    
    run = True
    while run:  
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
    
        window.fill(WHITE)
        window.blit(queenblacktext, (100, 100))
        pygame.display.flip()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 2021-11-11
      • 2018-09-05
      • 1970-01-01
      • 2020-06-23
      • 2015-05-09
      相关资源
      最近更新 更多