render text in pygame code example
Example 1: pygame render text
"""system font"""
font = pygame.font.SysFont("Segoe UI", 35)
"""font from .ttf file"""
font = pygame.font.Font("path/to/font.ttf", 35)
textsurface = font.render("text", False, color)
surface.blit(textsurface, (x, y))
Example 2: how to write a font in pygame
font = pygame.font.SysFont(None, 24)
img = font.render('hello', True, BLUE)
screen.blit(img, (20, 20))
Example 3: how to render text in pygame
pygame.font.init()
myfont = pygame.font.SysFont('Comic Sans MS', 30)
textsurface = myfont.render('Some Text', False, (0, 0, 0))
screen.blit(textsurface,(0,0))