Friday, January 10, 2014

Draw a pixel with PySDL2

This is a minimal code to output pixel on the screen using PySDL2.

UPD: (March 2014) Up for PySDL2 0.9.0 (RenderContext renamed to Renderer)
#!/usr/bin/env python
The code is placed into public domain
by anatoly techtonik <>
import sdl2
import sdl2.ext as lib


window = lib.Window('', size=(300, 100))

renderer = lib.Renderer(window)
renderer.draw_point([10,10], lib.Color(255,255,255))

running = True
while running:
  for e in lib.get_events():
    if e.type == sdl2.SDL_QUIT:
      running = False
    if e.type == sdl2.SDL_KEYDOWN:
      if e.key.keysym.sym == sdl2.SDLK_ESCAPE:
        running = False