O'Reilly logo

Raspberry Pi For Dummies by Mike Cook, Sean McManus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Importing Pygame

Before you can use Pygame, you need to import it, in the same way you imported the random module in Chapter 12. We’ll also be using the sys, time, and random modules for this game, so we need to import them too.

One of the modules in Pygame is called locals, and we’ll use its rect function for drawing rectangles, as well as some of its other features. So we don’t have to tell Python each time that the functionality we need is inside the locals module, we can import it in the second line of our program. It’ll save us time typing and make the program easier to read.

Here are the first two lines of our program:

# PiBuster from Raspberry Pi for Dummies

import pygame, sys, time, random

from pygame.locals import *

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required