pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## pygame

Contains the core routines that are used by the rest of the pygame modules. It's routines are merged directly into the pygame namespace. This mainly includes the auto-initialization init() and quit() routines.
There is a small module named 'locals' that also gets merged into this namespace. This contains all the constants needed by pygame. Object constructors also get placed into this namespace, you can call functions like Rect() and Surface() to create objects of that type. As a convenience, you can import the members of pygame.locals directly into your module's namespace with 'from pygame.locals import *'. Most of the pygame examples do this if you'd like to take a look.

Rect | - create a new rectangle
Surface | - create a new Surface
get_error | - get current error message
init | - autoinitialize all imported pygame modules
quit | - uninitialize all pygame modules
register_quit | - routine to call when pygame quits

Rect
`pygame.Rect(rectstyle) -> Rect`

Creates a new rectangle object. The given rectstyle represents one of the various ways of representing rectangle data. This is usually a sequence of x and y position for the topleft corner, and the width and height.
For some of the Rect methods there are two version. For example, there is move() and move_ip(). The methods witht the '_ip' suffix on the name are the 'in-place' version of those functions. They effect the actual source object, instead of returning a new Rect object.

Surface
`pygame.Surface(size, [flags, [Surface|depth, [masks]]]) -> Surface`

Creates a new surface object. Size is a 2-int-sequence containing width and height. Depth is the number of bits used per pixel. If omitted, depth will use the current display depth. Masks is a four item sequence containing the bitmask for r,g,b, and a. If omitted, masks will default to the usual values for the given bitdepth. Flags is a mix of the following flags: SWSURFACE, HWSURFACE, ASYNCBLIT, or SRCALPHA. (flags = 0 is the same as SWSURFACE). Depth and masks can be substituted for another surface object which will create the new surface with the same format as the given one. When using default masks, alpha will always be ignored unless you pass SRCALPHA as a flag. For a plain software surface, 0 can be used for the flag. A plain hardware surface can just use 1 for the flag.

get_error
`pygame.get_error() -> errorstring`

SDL maintains an internal current error message. This message is usually given to you when an SDL related exception occurs, but sometimes you may want to call this directly yourself.

init
`pygame.init() -> passed, failed`

Initialize all imported pygame modules. Including pygame modules that are not part of the base modules (like font and image).
It does not raise exceptions, but instead silently counts which modules have failed to init. The return argument contains a count of the number of modules initialized, and the number of modules that failed to initialize.
You can always initialize the modules you want by hand. The modules that need it have an init() and quit() routine built in, which you can call directly. They also have a get_init() routine which you can use to doublecheck the initialization. Note that the manual init() routines will raise an exception on error. Be aware that most platforms require the display module to be initialized before others. This init() will handle that for you, but if you initialize by hand, be aware of this constraint.
As with the manual init() routines. It is safe to call this init() as often as you like. If you have imported pygame modules since the.

quit
`pygame.quit() -> none`

Uninitialize all pygame modules that have been initialized. Even if you initialized the module by hand, this quit() will uninitialize it for you.
All the pygame modules are uninitialized automatically when your program exits, so you will usually not need this routine. If you program plans to keep running after it is done with pygame, then would be a good time to make this call.

register_quit
`pygame.register_quit(callback) -> None`

The given callback routine will be called when. pygame is quitting. Quit callbacks are served on a 'last in, first out' basis. Also be aware that your callback may be called more than once.