I
I
Ilya Garbazhiy2020-12-04 18:11:42
pygame
Ilya Garbazhiy, 2020-12-04 18:11:42

Pygame how to output katakana alphabet?

There is a code (I give below), which, in theory, should display a character of the Katakan alphabet.
It does not do this, but displays something like a pixel zero. Please help me figure out why and how to fix it.

PS font installed.

import pygame as p
import sys
import random2

p.init()
p.font.init()

# settings #
res = 800, 500
font_size = 40
FPS = 60
size = res[0]//font_size, res[1]//font_size

# pygame #
sc = p.display.set_mode(res)
p.display.set_caption("MATRIX")
font = p.font.SysFont("MS Mincho", font_size)
katakana = [chr(int('0x30a0', 16) + i) for i in range(96)]
matrix = [ [random2.choice(katakana) for i in range(size[0])] for i in range(size[1])]

print(matrix)

while True:
    sc.fill((0, 0, 0))
    # --- events --- #
    for event in p.event.get():
        if event.type == p.QUIT:
            p.quit()
            sys.exit(0)
    # --- drawing --- #
    symbol = font.render('メ', True, (0, 170, 0) )
    sc.blit( symbol, (100, 100) )

    p.display.update()
    p.time.delay(1//FPS)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2020-12-04
@WaterWalker

pygame.font.SysFont is used for system fonts.
If you have a file with a non-system font, try:
pygame.font.Font('MS Mincho.ttf', size)
where the first parameter is the font file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question