PiTFT PyGame Tips

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:

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

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

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

apt-get update
apt-get -y --force-yes install libsdl1.2debian/wheezy


sudo chmod +x installsdl.sh

sudo ./installsdl.sh

it will force install SDL 1.2

OK now you can continue with pygame

Last updated on 2017-09-22 at 01.23.38 PM Published on 2015-04-29 at 05.35.23 PM