Install
Get the package from PyPI.
pip install simple-graphics-lib
Simple Graphics is a small, readable layer over Pygame. Define shapes, decorate behavior, and let your program become a window.
01 / Start here
Install the package, make a thing, give it a heartbeat. Objects appear as soon as you create them.
Get the package from PyPI.
pip install simple-graphics-lib
Shapes register themselves in the scene.
from simple_graphics import *
ball = Circle(140, 120, 24,
color="#ff6b4a")
Decorators connect your logic to the loop.
@on_tick
def update():
ball.x += 2
run(400, 300)
Paste this into a file and run it with Python.
from simple_graphics import *
ball = Circle(80, 120, 24, color="#ff6b4a")
@on_tick
def move():
ball.x += 2
if ball.x > 400:
ball.x = 0
run(width=400, height=240, caption="A small beginning")
02 / The visual vocabulary
Every shape is a live Python object. Change its properties inside an event and the next frame reflects it.
Rect(x, y, width, height)
Rectangles, panels, paddles, cells, and buttons.
Circle(x, y, radius)
Round bodies for balls, planets, and markers.
Polygon(points)
Build custom silhouettes from a list of vertices.
Line(points, width=10)
Connect points into paths, hands, and boundaries.
Text(x, y, text)
Render labels and live game state in the scene.
Image(x, y, img_path)
Load, scale, and rotate an image asset.
color visible draggable
is_obj_over()
03 / Give it a heartbeat
Use a decorator to say when a function should run. Simple Graphics handles the Pygame event loop for you.
@on_tick
def update():
ball.x += velocity
ball.y += gravity
04 / Under the hood
Simple Graphics is built on Pygame, but provides a higher-level API for common beginner graphics tasks. Here is the same work in both libraries.
from simple_graphics import Circle, run
circle = Circle(200, 200, radius=50,
color="red")
run(400, 400)
Create a shape, then let run() manage the window and main loop.
pygame.init()
screen = pygame.display.set_mode((400, 400))
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("white")
pygame.draw.circle(screen, "red",
(200, 200), 50)
pygame.display.flip()
clock.tick(60)
Initialize the display, process events, draw each frame, and control the frame rate.
from simple_graphics import on_press, run
@on_press("space")
def pause():
print("Space pressed")
run()
Decorators connect input directly to the function that responds to it.
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif (event.type == pygame.KEYDOWN
and event.key == pygame.K_SPACE):
print("Space pressed")
Inspect each event and compare its type and key inside the event loop.
Pygame provides lower-level control over rendering, timing, and events. Simple Graphics reduces that boilerplate so you can focus on the behavior of your program.
05 / In the wild
The repository examples are deliberately approachable. Read one, change one number, and watch the system answer back.
Grid state, visibility, clicks, and timed evolution.
examples/life.pyNumerical simulation rendered one tick at a time.
examples/orbit.pyCollision detection, score state, and a tiny game loop.
examples/blockbreaker.pyLines, text, rotation, and the current time.
examples/clock.py05 / Keep close
These are the pieces you will reach for most often while building.
run(...)Start the window and main loop.set_bg(color)Set the background color.clear_screen()Remove every shape.erase(shape)Remove one shape.is_colliding(a, b)Check whether two shapes overlap.
mouse.x / mouse.yRead the current pointer position.
game.any_nameStore shared mutable game state.
Group(a, b, ...)Move and query shapes together.
shape.visibleKeep a shape in the scene but hide it.
shape.rotate(angle)Rotate supported shapes in degrees.