How to display text in pygame? [duplicate]

You can create a surface with text on it. For this take a look at this short example:

pygame.font.init() # you have to call this at the start, 
                   # if you want to use this module.
my_font = pygame.font.SysFont('Comic Sans MS', 30)

This creates a new object on which you can call the render method.

text_surface = my_font.render('Some Text', False, (0, 0, 0))

This creates a new surface with text already drawn onto it.
At the end you can just blit the text surface onto your main screen.

screen.blit(text_surface, (0,0))

Bear in mind, that every time the text changes, you have to recreate the surface again, to see the new text.

Leave a Comment