Game Development Reference
In-Depth Information
17 - Graphics and Animation
Figure 17-2: The "Hello World" program.
Importing the Pygame Module
Let's go over each of these lines of code and find out what they do.
1. import pygame, sys
2. from pygame.locals import *
First we need to import the pygame module so we can call the functions in the Pygame
software library. You can import several modules on the same line by delimiting the
module names with commas. Line 1 imports both the pygame and sys modules.
The second line imports the pygame.locals module. This module contains many
constant variables that we will use with Pygame such as QUIT or K_ESCAPE (which we
will explain later). However, using the form from moduleName import * we can
import the pygame.locals module but not have to type pygame.locals in front of
each time we use the module's functions and variables in our program. The * symbol
means we should import everything inside the module.
The pygame.locals module contains some constant variables we will use in this
program . If you have from sys import * instead of import sys in your program,
Search WWH ::




Custom Search