Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using PyGame to display on specified screen

1,085 views
Skip to first unread message

D.M. Procida

unread,
Apr 24, 2016, 4:23:34 AM4/24/16
to
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

Alex Potter

unread,
Apr 24, 2016, 10:30:20 AM4/24/16
to
ssh -t ?


--
Alex

D.M. Procida

unread,
Apr 24, 2016, 1:16:29 PM4/24/16
to
Alex Potter <spa...@alepot.org> wrote:

> > If I launch it using an SSH session, I get a "pygame.error: Unable to
> > open a console terminal" from 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?

> ssh -t ?

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

alister

unread,
Apr 24, 2016, 4:16:24 PM4/24/16
to
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
0 new messages