I am working on creating a graphical program to display two lines of text (a big message and a small message) on my Raspberry Pi Touchscreen using the module pygame. In the basic terminal, I can pass arguments to my program to display the messages for a few seconds as planned, but I am running into a problem.

My goal for the program is to display its graphics on top of a program, specifically Retroarch. I am planning to use this to periodically notify the player of the amount of time played. As of now, it appears that pygame is currently writing to somewhere that is not visible when Retroarch is running. I am thinking that I have to specify some additional parameter in order to display the graphics. I am wondering if writing to the framebuffer would enable me to achieve what I am trying to do. Any insight involving the framebuffer in relation to pygame and pi graphics modes would be great. I am excited to figure out what I need to do to achieve this!

(I have paused Retroarch using the kill command and its STOP flag, but this does not enable the GUI to display above Retroarch, either. This means the problem is not simply because Retroarch is running.)

All help is appreciated, thank you in advance! - nralego8

My code (if you're curious):

import pygame
import time
import sys

# Load arguments
big = " "
small = " "
if len(sys.argv) > 1:
    big = sys.argv[1]   

if len(sys.argv) > 2:
    small = sys.argv[2]

title = big + " | " + small 
if small == " ":
    title = big
if big == " ":
    title = " "

# Start pygame

# Set Up Screen Size and Positions
b_size = 75
s_size = int((2/3)*b_size)
dis = 0.25
display_width = 800
display_height = 480

gameDisplay = pygame.display.set_mode((display_width,display_height))

black = (0,0,0)
white = (255,255,255)
blue = (0,0,255)

clock = pygame.time.Clock()

def text_objects(text, font):
    textSurface = font.render(text, True, white)
    return textSurface, textSurface.get_rect()

def big_message(text):
    largeText = pygame.font.Font('freesansbold.ttf',b_size)
    TextSurf, TextRect = text_objects(text, largeText)
    TextRect.center = ((display_width/2),(display_height/(2+dis)))
    gameDisplay.blit(TextSurf, TextRect)

def small_message(text):
    largeText = pygame.font.Font('freesansbold.ttf',s_size)
    TextSurf, TextRect = text_objects(text, largeText)
    TextRect.center = ((display_width/2),(display_height/(2-dis)))
    gameDisplay.blit(TextSurf, TextRect)

def corner_logo(x,y):
    gameDisplay.blit(pygame.image.load('logo.png'), (display_width-x-5, display_height-y-5))



# I want the GUI to automatically close itself
  • what about using the linux notification system? – jsotola Mar 15 '19 at 5:44
  • You cannot use the notification system without starting x, right? My GUI is running from command line, without starting up x. – nralego8 Mar 18 '19 at 16:01
  • maybe this will work .... google pygame hud – jsotola Mar 18 '19 at 18:08

Your Answer

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

Browse other questions tagged or ask your own question.