3

I wanted to make a program with some cyrillic text in it. I made this code that would open up a window, have a title in Russian, and would put some Russian text (meaning Rasputin) on screen.The cyrillic font file supports cyrillic text.

import pygame as pg

pg.init()
pg.font.init()
font = pg.font.Font("Cyrillic-font.ttf",24)
gameDisplay = pg.display.set_mode((600, 400))
pg.display.set_caption("Распутин")


gameExit = False

while not gameExit:
    for event in pg.event.get():
        if event.type == pg.QUIT:
             gameExit = True
    gameDisplay.fill((255,255,255))
    text = font.render("Распутин",True,(255,0,0))
    gameDisplay.blit(text,(200,200)) 
    pg.display.update()
quit()

The program will display the text onto the screen. However, in the title, all that appears is "????????". I've attempted to use the font.render into the pg.display.set_caption(), but that wouldn't work as font.render gives a pygame surface instead of a string, so the code would stop.

  • 1
    It works for me with Ubuntu 18.10 - could it be the font used for the titlebar theme? – Kingsley Dec 18 '18 at 21:40
  • This problem also occurs for me on Windows 10, however I can change other title bars (e.g. command prompt `title Распутин`). – import random Dec 19 '18 at 00:13
  • @Kingsley It's most likely to be the problem, seeing that I have to use a special font to display the text onto the screen. Unfortunately I haven't figured out how to edit the font of the titlebar in pygame. – Oranje Maan Dec 21 '18 at 00:08
  • 1
    @OranjeMaan - I wondered if it was an encoding issue? Is that text "Распутин" encoded in UTF-8 (or unicode), or some other code-page? I came across a Japanese font the other day where the hiragana glyphs were mapped on latin A-Z, as opposed to wherever they should normally be indexed. Did you add the correct encoding header to python, e.g.: `# coding: utf-8` (must be 1st or 2nd line) - see http://python.org/dev/peps/pep-0263/ for details – Kingsley Dec 21 '18 at 00:14
  • @Kingsley I have checked the font file, as it also supported Latin characters along with some characters of other languages, the glyphs should be in their normal index. I didn't have an encoding header put in before. After adding one though, nothing has changed. – Oranje Maan Dec 21 '18 at 00:38
  • @Eric it seems to work for me as well if I do so. It seems the title in the command prompt and the title in the window pygame brings up should be using the same font. Thus, I have now realized the problem is unlikely the font being unable to display the message. – Oranje Maan Dec 21 '18 at 00:50
  • This might be a limitation of SDL on Windows. A possible solution is to remove the default title bar with `pygame.NOFRAME` implement it yourself. – Maximouse Feb 19 '20 at 13:32
  • [Related SDL question](https://stackoverflow.com/questions/53741550/how-do-i-use-accented-characters-in-the-window-title-in-sdl2) – Maximouse Feb 19 '20 at 13:33

1 Answers1

-1

In my opinion, it is an operative system design failure.

In windows 10 Pro I just changed "Region Settings" to Russian. Find it in "Region, Administrative". All keep old language and text Russian text has Cyrillic letters.

Maybe is not the best solution, but it works.

colidyre
  • 4,170
  • 12
  • 37
  • 53