- Pygame - Discussion
- Pygame - Useful Resources
- Pygame - Quick Guide
- Pygame - Errors and Exception
- Pygame - PyOpenGL
- Pygame - The Sprite Module
- Pygame - Access CDROM
- Pygame - Load cursor
- Pygame - Using Camera module
- Pygame - Playing Movie
- Pygame - Playing music
- Pygame - Mixer channels
- Pygame - Sound objects
- Pygame - Transforming Images
- Pygame - Use Text as Buttons
- Pygame - Moving Rectangular objects
- Pygame - Moving with mouse
- Pygame - Moving with Numeric pad keys
- Pygame - Moving an image
- Pygame - Displaying Text in Window
- Pygame - Loading image
- Pygame - Drawing shapes
- Pygame - Mouse events
- Pygame - Keyboard events
- Pygame - Event objects
- Pygame - Color object
- Pygame - Locals module
- Pygame - Display modes
- Pygame - Hello World
- Pygame - Overview
- Pygame - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pygame - Overview
Pygame is a popular Python pbrary used for developing video games. It is free, open source and cross-platform wrapper around Simple DirectMedia Library (SDL). Abstraction of SDL functions provided by Pygame makes development of multi-media apppcations using Python very easy.
Originally developed by Peter Shinners, Lenard Lindstrom, René Dudfield and others in Oct 2000, latest version of Pygame is 2.0.1, released in Dec 2020. In addition to SDL functionapty, Pygame also provides other features such as vector maths, colpsion detection, camera and MIDI support etc. Pygame apppcations can be used on Android based mobile phones also.
Environment Setup
Easiest way to install Pygame on any machine is by using PIP installer that comes with standard Python distribution. Ensure that you have latest version of pip. It is recommended to install Pygame in a new virtual environment using following command −
pip3 install pygame
For Raspberri Pi, Pygame is pre-installed in raspbian Linus distribution. As far as installation on MacOS is concerned, newer versions require Pygame 2.0. Prebuilt binary packages are available for many flavours of Linux. They can be installed using respective package manager utipties.
For Ubuntu, following is the command −
sudo apt-get install pygame
For Fedora, the following is the command −
sudo yum install pygame
It is also possible to compile Pygame’s source code (available at
and install on desired operating system with the help of respective C/C++ compiler and Python’s setuptools pbrary.To verify if Pygame has been successfully installed, try and import pygame package and check its version.
(pygmenv) C:pygmenv>python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "pcense" for more information. >>> import pygame pygame 2.0.1 (SDL 2.0.14, Python 3.7.4) Hello from the pygame community. https://www.pygame.org/contribute.html
Pygame pbrary consists of following modules −
pygame._sdl2.touch | to work with touch input |
pygame.camera | camera use |
pygame.cdrom | audio cdrom control |
pygame.cursors | cursor resources |
pygame.display | to control the display window and screen |
pygame.draw | drawing shapes |
pygame.event | interacting with events and queues |
pygame.examples | module of example programs |
pygame.fastevent | interacting with events and queues from multiple threads. |
pygame.font | loading and rendering fonts |
pygame.freetype | loading and rendering computer fonts |
pygame.gfxdraw | drawing shapes |
pygame.image | image transfer |
pygame.joystick | interacting with joysticks, gamepads, and trackballs. |
pygame.key | to work with the keyboard |
pygame.locals | pygame constants |
pygame.mask | image masks. |
pygame.math | vector classes |
pygame.midi | interacting with midi input and output. |
pygame.mixer | loading and playing sounds |
pygame.mixer.music | controlpng streamed audio |
pygame.mouse | to work with the mouse |
pygame.pixelcopy | general pixel array copying |
pygame.scrap | cppboard support. |
pygame.sndarray | accessing sound sample data |
pygame.sprite | basic game object classes |
pygame.surfarray | accessing surface pixel data using array interfaces |
pygame.tests | unit test suite package |
pygame.time | monitoring time |
pygame.transform | to transform surfaces |