Book
Module 4 - Section 2 - Graphics
Module 4 - Section 2 - Graphics
Completion requirements
View
After the completion of this module the students will be able to:
- identify the commands inside the Pygame basic template
- experiment with various graphics commands
- draw shapes using Python commands
- draw text using Python commands
4.2.8 - Drawing Text
- First, create a variable that holds information about the font to be used, such as what typeface and how big.
font = SysFont(name, size, bold=False, italic=False) - Second, create an image of the text. One way to think of it is that the program carves out a “stamp” with the required letters that is ready to be dipped in ink and stamped on the paper.
text = font.render(text, antialias, color, background=None)
- Tthird, write where this image of the text should be stamped (or “blit'ed”) to the screen.
screen.blit(text, [250, 250])
Starting from the pygame basic template write the commands inside the drawing section:
font = pygame.font.SysFont('Calibri', 25, True, False) # in line 47
text = font.render("My text",True,BLACK) # in line 48
screen.blit(text, [250, 250]) # in line 49
and save the script as simple_text.
Experiment combining different shapes and text and creating your own picture.