External Exam Download Resources Web Applications Games Recycle Bin

Text (with colour)

text_with_colour.py

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

salmon = (250,128,114) # (R, G, B) red green blue (tuple)
game_font = pygame.font.SysFont("papyrus", 96) # font, px
text_image = game_font.render("eshay lad", True, salmon) # .render(text, anti-alias?, colour)

while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True

  screen.blit(text_image, (20, 20)) # (x, y)
  
  pygame.display.flip()
pygame.quit()

text (font) renders as an image. end result:


To load a font file in your project directory:

pygame.font.Font("myfont.ttf", size)

To see a list of system font strings:

pygame.font.get_fonts()