1

I added the function print_text giving to write texts, but texts can't show on my program. Solve the problem, please)

pygame.font.init()
#[...]
def print_text(message, x, y, font_color = (0,0,0), font_type = 'shrift.ttf', font_size = 30):
    font_type = pygame.font.Font(font_type)
    text = font_type.render(message, True, font_color)
    display.blit(text, (x,y))
running = True
while running:
    clock.tick(FPS)
    for event in pygame.event.get():
    #[...]
    print_text('Hello, my friend!', 650, 100)
    pygame.display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Vildan
  • 131
  • 6

1 Answers1

1

pygame.font.Font needs to arguments. The font and the size:

font_type = pygame.font.Font(font_type)

font_type = pygame.font.Font(font_type, font_size)

If pygame.font.Font doesn't work use pygame.font.SysFont instead:

font_type = pygame.font.SysFont(font_type, font_size)

You are drawing black text in a black window. Change the color of the text. e.g:

print_text('Hello, my friend!', 650, 100)

print_text('Hello, my friend!', 650, 100, "red")
Rabbid76
  • 202,892
  • 27
  • 131
  • 174