使用 pygame 显示 unicode 符号 [英] Displaying unicode symbols using pygame

查看:56
本文介绍了使用 pygame 显示 unicode 符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了其他答案,但不明白为什么我的代码显示错误 ♔.

这里是文字渲染的相关代码.

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())打印.

或者下载字体

导入pygame白色 = (255, 255, 255)黑色 = (0, 0, 0)pygame.init()窗口 = pygame.display.set_mode((500, 500))seguisy80 = pygame.font.SysFont("segoeuisymbol", 80)Queenblack = "♔";Queenblacktext = seguisy80.render(queenblack, True, BLACK)运行 = 真运行时:对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:运行 = 错误window.fill(白色)window.blit(queenblacktext, (100, 100))pygame.display.flip()

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.

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

All help us appreciated, thanks. Im using python 3.8, and using Pycharm.

解决方案

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()

这篇关于使用 pygame 显示 unicode 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆