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 python3-pip

Install Pygame: sudo apt-get install python3-pygame

(this will take a while)

Running SDL 1.2

If you experience issues with the current version of SDL, you can try running an older version. 

Some versions of 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
and paste in the following text:


# enable wheezy package sources
echo "deb 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


sudo 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 Apr 29, 2015. It was last updated on Apr 04, 2024.

This page (PiTFT PyGame Tips) was last updated on Apr 04, 2024.

Text editor powered by tinymce.