Since the PiTFT screen is fairly small, you may need to write custom UI programs. Pygame is the easiest way by far to do this.

Jeremy Blythe has an excellent tutorial here on getting started. 

However, before you follow that link you'll want to set up pygame for the best compatibility:

Install pip & pygame

Install Pip: sudo apt-get install python-pip

Install Pygame: sudo apt-get install python-pygame

(this will take a while)

Ensure you are running SDL 1.2

SDL 2.x and SDL 1.2.15-10 have some serious incompatibilities with touchscreen. You can force SDL 1.2 by running a script. (Thanks to heine in the forums!)

Edit a new file with sudo nano installsdl.sh
and paste in the following text:

#!/bin/bash

# enable wheezy package sources
echo "deb http://legacy.raspbian.org/raspbian wheezy main
" > /etc/apt/sources.list.d/wheezy.list

# set stable as default package source (currently buster)
echo "APT::Default-release \"stable\";
" > /etc/apt/apt.conf.d/10defaultRelease

# set the priority for libsdl from wheezy higher then the buster package
echo "Package: libsdl1.2debian
Pin: release n=buster
Pin-Priority: -10
Package: libsdl1.2debian
Pin: release n=wheezy
Pin-Priority: 900
" > /etc/apt/preferences.d/libsdl

# install
apt-get update
apt-get -y --allow-downgrades install libsdl1.2debian/wheezy

run

sudo sh ./installsdl.sh

it will force install SDL 1.2

OK now you can continue with pygame

Using the Capacitive touch screen in PyGame

The 2.8" Capacitive touch screen driver may not work by default in pygame, but this handy script shows how you can capture the device messages in python to create a UI

This guide was first published on Nov 29, 2013. It was last updated on Mar 08, 2024.

This page (PiTFT PyGame Tips) was last updated on Mar 08, 2024.

Text editor powered by tinymce.