Displaying unicode symbols using pygame

后端 未结 1 1448
遇见更好的自我
遇见更好的自我 2021-01-23 10:02

I\'ve checked other answers, but cant see why my code incorrectly displays ♔.

This is what I currently see

Here is the relevant code about the text rendering.

相关标签:
1条回答
  • 2021-01-23 10:22

    The unicode character is not provided by the "Tahoma" font.

    Use the "segoeuisymbol" font if your system supports it:

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

    Note, the supported fonts can be print by print(pygame.font.get_fonts()).

    Alternatively download the font Segoe UI Symbol and create a pygame.font.Font

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

    Use the font to render the sign:

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

    Minimal example:

    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()
    
    0 讨论(0)
提交回复
热议问题