Python display text with font & color?

后端 未结 5 1268
醉话见心
醉话见心 2020-12-05 06:16

Is there a way I can display text on a pygame window using python?

I need to display a bunch of live information that updates and would rather not make an image for

5条回答
  •  天命终不由人
    2020-12-05 06:44

    You can use your own custom fonts by setting the font path using pygame.font.Font

    pygame.font.Font(filename, size): return Font
    

    example:

    pygame.font.init()
    font_path = "./fonts/newfont.ttf"
    font_size = 32
    fontObj = pygame.font.Font(font_path, font_size)
    

    Then render the font using fontObj.render and blit to a surface as in veiset's answer above. :)

提交回复
热议问题