问题描述
这是有关文本渲染的相关代码。
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并创建一个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)
pygame.init()
window = pygame.display.set_mode((500,500))
seguisy80 = pygame.font.SysFont("segoeuisymbol",80)
queenblack = "♔"
queenblacktext = seguisy80.render(queenblack,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()