Sometimes, we want to display text with font and color with Python pygame.
In this article, we’ll look at how to display text with font and color with Python pygame.
How to display text with font and color with Python pygame?
To display text with font and color with Python pygame, we can call pynamd.font.SysFont
to set the font.
And we call render
to set the color.
For instance, we write
my_font = pygame.font.SysFont("monospace", 15)
label = my_font.render("hello!", 1, (255, 255, 0))
screen.blit(label, (100, 100))
to call pygame.font.SysFont
with the font name and size.
And then we call my_font.render
with the text to render and a tuple with the rgb color values as the 3rd argument.
Conclusion
To display text with font and color with Python pygame, we can call pynamd.font.SysFont
to set the font.