Raspberry Pi Pygame UI basics Overview
Raspberry Pi Pygame UI basics
published February 01, 2016, last edited March 08, 2024
Featured Productsview all
38
Beginner
Project guide
Overview
Before diving in to this tutorial, first follow the setup instructions for your PiTFT. Make sure to choose the correct guide particularly forresistive vscapacitive displays and carefully follow the section onPiTFT Pygame Tips - in particular you really need SDL 1.2!
You can also grab all the tutorial source code from git:
git clone https://github.com/jerbly/tutorials.git
git clone https://github.com/jerbly/tutorials.git
To test the display you can run through these steps in the python console:
pi@raspberrypi ~ $ sudo pythonPython 2.7.3 (default, Mar 18 2014, 05:13:23)[GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pygame>>> import os>>> os.putenv('SDL_FBDEV', '/dev/fb1')>>> pygame.init()(6, 0)>>> lcd = pygame.display.set_mode((320, 240))>>> lcd.fill((255,0,0))<rect(0, 0, 320, 240)>>>> pygame.display.update()>>> pygame.mouse.set_visible(False)1>>> lcd.fill((0,0,0))<rect(0, 0, 320, 240)>>>> pygame.display.update()
pi@raspberrypi ~ $ sudo pythonPython 2.7.3 (default, Mar 18 2014, 05:13:23)[GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pygame>>> import os>>> os.putenv('SDL_FBDEV', '/dev/fb1')>>> pygame.init()(6, 0)>>> lcd = pygame.display.set_mode((320, 240))>>> lcd.fill((255,0,0))<rect(0, 0, 320, 240)>>>> pygame.display.update()>>> pygame.mouse.set_visible(False)1>>> lcd.fill((0,0,0))<rect(0, 0, 320, 240)>>>> pygame.display.update()
you may also need to try
os.putenv('SDL_VIDEODRIVER', 'fbcon') # Force PyGame to PiTFT
in the beginning, if pygame isn't appearing
You can also run this test (with a one second sleep) from the pygamelcd project:
OK now you're ready!
Page last edited March 08, 2024
Text editor powered bytinymce.