Menu
CoddyTech

Fill the Background

Lesson 2 of 40 in Coddy's Make Games with Pygame course.

Pygame describes a colour as three numbers: how much red, green and blue it has, each from 0 to 255. This is called RGB.

  • (255, 0, 0) is red.
  • (0, 0, 0) is black, (255, 255, 255) is white.
  • (30, 30, 46) has a little more blue than red and green: a dark blue.

screen.fill(color) paints the whole window in one colour. Games fill the screen at the start of every frame, which wipes out the last frame before the new one is drawn.

screen.fill((0, 0, 0))
pygame.display.flip()

Note the double brackets: the colour is one tuple, the only argument of fill.

challenge icon

Challenge

Easy

Inside the game loop, above pygame.display.flip(), fill the screen with the dark blue (30, 30, 46).

Try it yourself

import pygame

pygame.init()
screen = pygame.display.set_mode((480, 360))
pygame.display.set_caption("Move the Square")

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    pygame.display.flip()

pygame.quit()
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Make Games with Pygame

Practice on your own: Pygame playground