使用 pygame 显示 unicode 符号

Displaying unicode symbols using pygame

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

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.

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

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

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

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

或者下载字体Segoe UI Symbol and create a 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()