Fred B
Fred B

Reputation: 99

Displaying unicode symbols using pygame

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.

Upvotes: 2

Views: 1211

Answers (1)

Rabbid76
Rabbid76

Reputation: 211116

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

Upvotes: 2

Related Questions