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.3 - Windows
So far, the programs that wrote created only printed text to the CLI area. Those programs did not open any windows like most modern programs do. The code to open a window is not complex. Below is the required code, which creates a window sized to a width of 700 pixels, and a height of 500:
Opening and setting the window size :
>>> size = (700, 500) # Size can also be either a tuple or a list. Which do you think is better?
>>> screen = pygame.display.set_mode(size)
With the second command pygame is not opening a window but it is setting the parameters (size) of the window. Size is also a list of two numbers.
We can also set the title of the window with the command :
>>> pygame.display.set_caption("My Game")