Skip to content
A small Python 3.x media library, with a very simple API.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A small Python 3.x media library, with a very simple API.


import pslab

window = pslab.Window(640, 480)               # You have a 640 x 480 window.
window.setTitle("Pslab Test")                 # A title for your window (optional)

window[0] = 0xFF0000                          # Set color of first pixel to red.
window[1] = 0x00FF00                          # Second pixel to blue.
window[2] = 0x0000FF                          # Third to green.

window.update()                               # See the changes (you might have to squint).

window.fill(0xFF0000)                         # Make the whole screen red.

window.update()                               # See the changes (you won't have to squint this time).

slab = pslab.Slab(64, 64)                     # Create a 64 x 64 slab of pixels (black by default).
slab.fill(0xFFFFFF)                           # Make it white.
slab.burnInto(window)                         # Burn the white slab into the red window, at origin.
window.update()                               # See the changes.

slab.fill(0x0000FF)                           # Make slab blue.
slab.burnInto(window, 64, 64)                 # Burn the blue slab into the red window, at x:64, y:64.

for i in range(64 * 32):                      # Color the first half of the slab green.
	slab[i] = 0x00FF00

slab.burnInto(window, 128, 128)               # ... I think you got the idea.

window.fill(0)                                # Clear the screen to black.

slab = pslab.SlabImg("path/to/image.jpeg")    # Slab of pixels formed from an image.
slab.burnInto(window)                         # Other than that, it's just a regular slab.
window.update()                               # As you can see.

 # Text:


font_path = "/path/to/font.ttf"
point_size = 12
color_char = 0xFFFFFF
color_background = 0
text = "Hello World."

slab = pslab.SlabText(font_path, point_size, color_char, color_background, text)

slab.update()                                 # Changing text requires update - text is rendered to slab.
slab.burnInto(window, 0, 12)

slab.setColor(0x0000FF, 0xFF0000)
slab.setText("Hello weird world.")
slab.burnInto(window, 0, 24)

 # Sound

sound = pslab.Sound("path/to/sound.wav")

 # Mouse input

import time
import random

mouse = window.mouse

while True:
	window.processEvents()                # Updates the mouse object with relevant data

	if mouse.btnHit("rmb"):               # Clicking right mouse button breaks loop

	if mouse.btnHit("lmb"):               # Clicking left mouse button marks the coordinate

		mx, my = mouse.getPosition()
		slab.setText("mx:{:d}, my:{:d}".format(mx, my))
		slab.setColor(random.randint(0, 0xFFFFFF), 0)
		slab.burnInto(window, mx, my)

	time.sleep(1/30)                      # Don't hog CPU


 # Keyboard input

kb = window.keyboard
pos = [0, 0]
spd = 5

while True:

	# Both keyDown and keyHit take either a single char, representing the respective key,
	# or one of the following label strings:
	# "enter", "esc", "space", "up", "down"
	# "left", "right", "rshift", "lshift"
	# "rctrl", "lctrl", "ralt", "lalt"
	right_left = kb.keyDown("right") - kb.keyDown("left")
	up_down = kb.keyDown("down") - kb.keyDown("up")

	if right_left or up_down:
		pos[0] += spd * right_left
		pos[1] += spd * up_down
		slab.burnInto(window, *pos)

	if kb.keyHit('q') or kb.keyHit("esc"):



This library requires SDL 1.2, and complementary libraries (SDL_image, SDL_ttf and SDL_mixer). These are all C shared libraries that must be in your library path.

  • Linux: you can simply use your package manager to get the respective SDL development packages.
  • Windows: get the SDL dlls however you can, and make sure they are in your path.
  • OSX: make sure that the SDL libraries are in your library path.

With that done, you can cd into pslab/demos/minimem, and run python to test the system.

If everything works right, you can "install" this python library by moving and ctypesdl into a directory like "site-packages", which is typically used for third party python modules like this one. Although, any directory in your python path should work equally well.

At this point, you should be able to import pslab in any Python 3.x program, anywhere on your system.

You can’t perform that action at this time.