5.0.3 - Pygame basics

For a new Pygame project we can start from the Pygame basic template

Let's review the series of commands :

import pygame # it imports the library pygame

pygame.init() # starts the pygame 

size = (700,500) # Set the width and height of the screen

screen = pygame.display.set_mode(size) # creates a window and name it screen

pygame.display.set_caption("My Game") # This is the name on the top of the window

done = False # We create a variable that is called done and when this variable turns to True, during the game, the game stops.

clock = pygame.time.Clock() # It controls the refresh rate

Event processing. 

for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

screen.fill(WHITE) # background is WHITE. 

pygame.display.flip() # update the screen

clock.tick(60) # refresh 60 times a second

pygame.quit() # Close the window and quit.