1

I am trying to display text (actually wingding characters once I get past this problem) on top of all other desktop windows (similar to a HUD or OSD).

The following is a test which takes the text that gets passed via command line and displays it using pygame. I do not know how I can get the text to not have any background, ie. nothing should cover the other windows there should be just hovering text.

I looked at pyosd but it is poorly documented and doesn't seem to support TrueType fonts.

Any pointers are appreciated.

#!/usr/bin/python
# source: https://sivasantosh.wordpress.com/2012/07/18/displaying-text-in-pygame/
import pygame, sys, time
from pygame.locals import *

pygame.init()

backgroundcolor = 0, 0, 0
textcolor = 255, 255, 0
fontsize = 120
displaytext = str(sys.argv[1])
displayduration = 10

infoObject = pygame.display.Info()
size = [infoObject.current_w, infoObject.current_h]
pygame.display.set_caption('font example')
screen = pygame.display.set_mode(size)
basicfont = pygame.font.SysFont(None, fontsize)

def DisplayMessage(string):
    text = basicfont.render(string, False, (textcolor)).convert_alpha()
    textrect = text.get_rect()
    textrect.centerx = screen.get_rect().centerx
    textrect.centery = screen.get_rect().centery
    screen.blit(text, textrect)
    pygame.display.update()
    time.sleep(displayduration)

DisplayMessage(displaytext.decode("utf-8"))
sys.exit()
PiEnthusiast
  • 314
  • 1
  • 4
  • 19

0 Answers0