pygame - Pygame Documentation

pygame documentation | || Pygame Home || Help Contents || Reference Index || Camera || Cdrom || Color || Cursors || Display || Draw || Event || Examples || Font || Gfxdraw || Image || Joystick || Key || Locals || Mask || Midi || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Tests || Time || Transform

pygame

the top level pygame package

pygame.init - initialize all imported pygame modules | initialize all imported pygame modules
pygame.quit - uninitialize all pygame modules | uninitialize all pygame modules
pygame.error - standard pygame exception | standard pygame exception
pygame.get_error - get the current error message | get the current error message
pygame.set_error - set the current error message | set the current error message
pygame.get_sdl_version - get the version number of SDL | get the version number of SDL
pygame.get_sdl_byteorder - get the byte order of SDL | get the byte order of SDL
pygame.register_quit - register a function to be called when pygame quits | register a function to be called when pygame quits
pygame.version - small module containing version information | small module containing version information

The pygame package represents the top-level package for others to use. Pygame itself is broken into many submodules, but this does not affect programs that use Pygame.

As a convenience, most of the top-level variables in pygame have been placed inside a module named `'pygame.locals'`. This is meant to be used with 'from `pygame.locals` import *', in addition to 'import pygame'.

When you 'import pygame' all available pygame submodules are automatically imported. Be aware that some of the pygame modules are considered "optional", and may not be available. In that case, Pygame will provide a placeholder object instead of the module, which can be used to test for availability.

pygame.init

initialize all imported pygame modules
`pygame.init(): return (numpass, numfail)`

Initialize all imported Pygame modules. No exceptions will be raised if a module fails, but the total number if successful and failed inits will be returned as a tuple. You can always initialize individual modules manually, but `pygame.init` is a convenient way to get everything started. The init() functions for individual modules will raise exceptions when they fail.

You may want to initalise the different modules seperately to speed up your program or to not use things your game does not.

It is safe to call this init() more than once: repeated calls will have no effect. This is true even if you have `pygame.quit - uninitialize all pygame modules` all the modules.

pygame.quit

uninitialize all pygame modules
`pygame.quit(): return None`

Uninitialize all pygame modules that have previously been initialized. When the Python interpreter shuts down, this method is called regardless, so your program should not need it, except when it wants to terminate its pygame resources and continue. It is safe to call this function more than once: repeated calls have no effect.

Note, that `pygame.quit` will not exit your program. Consider letting your program end in the same way a normal python program will end.

pygame.error

standard pygame exception
`raise pygame.error, message`

This exception is raised whenever a pygame or `SDL` operation fails. You can catch any anticipated problems and deal with the error. The exception is always raised with a descriptive message about the problem.

Derived from the RuntimeError exception, which can also be used to catch these raised errors.

pygame.get_error

get the current error message
`pygame.get_error(): return errorstr`

`SDL` maintains an internal error message. This message will usually be given to you when `pygame.error` is raised. You will rarely need to call this function.

pygame.set_error

set the current error message
`pygame.set_error(error_msg): return None`

`SDL` maintains an internal error message. This message will usually be given to you when `pygame.error` is raised. You will rarely need to call this function.

pygame.get_sdl_version

get the version number of SDL
`pygame.get_sdl_version(): return major, minor, patch`

Returns the three version numbers of the `SDL` library. This version is built at compile time. It can be used to detect which features may not be available through Pygame.

get_sdl_version is new in pygame `1.7.0`

pygame.get_sdl_byteorder

get the byte order of SDL
`pygame.get_sdl_byteorder(): return int`

Returns the byte order of the `SDL` library. It returns `LIL_ENDIAN` for little endian byte order and `BIG_ENDIAN` for big endian byte order.

get_sdl_byteorder is new in pygame `1.8`

pygame.register_quit

register a function to be called when pygame quits
`register_quit(callable): return None`

When `pygame.quit` is called, all registered quit functions are called. Pygame modules do this automatically when they are initializing. This function is not be needed for regular pygame users.

pygame.version

small module containing version information
`module pygame.version`

pygame.version.ver - version number as a string | version number as a string
pygame.version.vernum - tupled integers of the version | tupled integers of the version

This module is automatically imported into the pygame package and offers a few variables to check with version of pygame has been imported.

pygame.version.ver

version number as a string
`pygame.version.ver = '1.2'`

This is the version represented as a string. It can contain a micro release number as well, `e.g.`, `'1.5.2'`

pygame.version.vernum

tupled integers of the version
`pygame.version.vernum = (1, 5, 3)`

This variable for the version can easily be compared with other version numbers of the same format. An example of checking Pygame version numbers would look like this:

        if pygame.version.vernum < (1, 5):
            print 'Warning, older version of Pygame (%s)' %  pygame.version.ver
            disable_advanced_features = True