pygame 文本 字体

import pygame
import pygame.freetype  # Import the freetype module.


pygame.init()
screen = pygame.display.set_mode((400, 300))
GAME_FONT = pygame.freetype.Font("/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", 24)
running =  True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill((255,255,255))
    # You can use `render` and then blit the text surface ...
    text_surface, rect = GAME_FONT.render("12", (0, 0, 0))
    screen.blit(text_surface, (40, 150))
    # or just `render_to` the target surface.
    GAME_FONT.render_to(screen, (40, 50), "Hello 34567890", (0, 0, 0))

    pygame.display.flip()

pygame.quit()


版权声明:本文为CAIYUNFREEDOM原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。