Pygame is a set of modules designed for writing video games, or other multimedia programs in the Python ποΈ programming language. It is built on top of the Simple DirectMedia Layer π library (SDL), and is meant to abstract the most common functions to make development faster / easier.
Pygame is highly portable and runs on almost every platform / operating system.
It is free and open-source, and distributed under a LGPL licence, meaning that anyone can create open source, freeware, shareware, or commercial games with it.
Installation with pip:
pip install pygame
Installation instructions from official docs:
python3 -m pip install -U pygame --user
(the --user
flag installs pygame into the home directory, instead of globally)
Simple example game structure:
import pygame
WIDTH, HEIGHT = 700, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Simple Game")
FPS = 60
def draw_screen():
WIN.fill("blue")
pygame.display.update()
def main():
run = True
clock = pygame.time.Clock()
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_screen()
if __name__ == "__main__":
main()
import pygame
pygame.display.set_mode()
pygame.display.set_caption()
pygame.display.update()
main()
function