Unicode mapping in pygame

I want to display some unicode characters on the screen.

Using pygame.font displays a weird character.

 import pygame pygame.init() screen = pygame.display.set_mode((500, 500)) pygame.display.set_caption("TEST") FONT = pygame.font.Font(None, 64) font_surf = FONT.render("โ™›", True, pygame.Color("red")) screen.blit(font_surf, (20, 20)) pygame.display.flip() pygame.time.delay(1000) 

I also tried using pygame.freetype. It does not display anything.

 import pygame.freetype pygame.freetype.init() screen = pygame.display.set_mode((500, 500)) pygame.display.set_caption("TEST") FONT = pygame.freetype.Font(None) FONT.render_to(screen, (20, 20), "โ™›", size=(40, 40)) pygame.display.flip() pygame.time.delay(1000) 
+4
source share
1 answer

working 3.4 unicode

You need to add the name and location of the font.

 f = pygame.font.Font("segoe-ui-symbol.ttf",64) 

In Python 3.4, you no longer need u until "โ™›" , as in Python 2.7.

  unistr = "โ™›" 

based on this other link, but for 3.4 as an example - 2.7

 # -*- coding: utf-8 -*- import pygame import sys unistr = "โ™›" pygame.font.init() srf = pygame.display.set_mode((500,500)) f = pygame.font.Font("segoe-ui-symbol.ttf",64) srf.blit(f.render(unistr,True,(255,0,0)),(0,0)) pygame.display.flip() while True: srf.blit(f.render(unistr,True,(255,255,255)),(0,0)) for e in pygame.event.get(): if e.type == pygame.QUIT: pygame.quit() sys.exit() 
+4
source

All Articles