Using PyGame to display on specified screen

Apr 24, 2016 3 Replies

I have a Raspberry Pi, and I want to get PyGame to display output on the attached 7" touchscreen, no matter how I launch the script to do this.



If I launch it from a terminal shell while using the 7" screen, it works.



If I launch it using an SSH session, I get a "pygame.error: Unable to open a console terminal" from pygame.display.init().



If I launch it from a terminal shell in a VNC session, it displays in the VNC display.



Here's relevant part of the script:



import pygame import os



os.environ['SDL_VIDEODRIVER'] = 'fbcon' os.environ["SDL_FBDEV"] = "/dev/fb0"



pygame.init()



pygame.display.init()



So far, the only way I can get this to work is to launch the script with:



DISPLAY=:0 python pygame_example.py



It seems that setting the os.environ values in the script has no effect whatsoever.



What is the correct way to do this?



Daniele


Same result. But in any case, I was hoping to manage this in the script itself. It seems reasonable that a program should be able to determine where its own output goes.

Daniele

perhaps creating a bash script containing your working example.

this would be in keeping with the unix philosophy of combining simple tools that each perform as single task (well)

Caveats: it's GNOME, be afraid, be very afraid of the Depends line -- James Troup

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required