Using PyGame to display on specified screen

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

Reply to
D.M. Procida
Loading thread data ...

ssh -t ?

--
Alex
Reply to
Alex Potter

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

Reply to
D.M. Procida

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
Reply to
alister

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.