I'm using Buildroot 2018.02 to create a custom Linux to run my raspberry pi 3.

I'm trying to display a pygame window on the external hdmi screen from command line.

So far, I've been able to boot the pi3 with the default configuration running make raspberrypi3_defconfig, I've just changed the toolchain to use glibc instead of uClibc-ng.

Flashing the first default configuration

make raspberrypi3_defconfig
make menuconfig
dd if=output/images/sdcard.img of=/dev/sdb bs=4M

The rpi boot well, I can log as root using a FTDI cable.

Adding pygame ans ssh support

I run make menuconfig to select both open-ssh and python3 packages and I select the external python3 package python-pygame

After reflashing, the rpi boots well and I can connect through ssh.

At this moment nothing is printed on the hdmi screen. If I open a pygame window running a python3 shell nothing happens.

# python3
Python 3.6.3 (default, Jun 17 2018, 20:05:31) 
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> screen = pygame.display.set_mode((300, 200))
>>> pygame.display.flip()
>>> quit()

Adding X.org support

I have then enabled X.org X Window System with the following configuration.


At this moment, when the rpi3 boot, I can see kernel logs on the hdmi screen. If I run startx from command line, several windows appear as follow enter image description here

However if I run again the python instructions above, the screen become totally black.
If I quit the python shell, the screen returns to the picture state.

I have also tried after exporting display with export DISPLAY=:0.0 but with the same result.

If I don't run startx the result is the same except that console log replace the windows on the picture.

What else could I do to be able to display a pygame window from command line ?


Pygame is not a framework where button, frame and windows are already defined. It is a more low level access to the framebuffer.

To use pygame with the framebuffer you should write something into it. Basically, your program only declares the screen (which is initially black) and... do nothing else.

You should use blit to write/place texts and images to the framebuffer. Then call flip to actually show/render your screen.

A basic example is as follow :

import pygame
from pygame.locals import *

pygame.display.init() ;

(width,height) = (800,480)
screen = pygame.display.set_mode((width, height))

font = pygame.font.SysFont("cantarell", 24)

text = font.render('Text to show',True,(200,0,0))
image = pygame.image.load ('image.jpg')

while True:
    # clear the screen
    screen.fill((0, 0, 0))
    # place the image
    screen.blit(image, (0, 0))
    # the the image
    # render/update the display

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.