Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active August 14, 2025 21:43
Show Gist options
  • Save todbot/b966f51307aca8dab64af70dc2954aee to your computer and use it in GitHub Desktop.
Save todbot/b966f51307aca8dab64af70dc2954aee to your computer and use it in GitHub Desktop.
playing with adafruit circuitpython-fonts package
# circuitpython_font_play_code_simple.py -- playing w adafruit circuitpython-fonts
# 8 Aug 2025 - @todbot / Tod Kurt
# developed on a Lilygo T-Display S3 w/ ST7789 display in paralleldisplaybus mode
# To use this, first install 'circup' and do what's described here:
# https://github.com/adafruit/circuitpython-fonts/
# e.g.:
# circup bundle-add adafruit/circuitpython-fonts # You only need to do this once
# circup show | grep 48 | grep font # find fonts that are size 48
# circup install font_... # find a font you like & install it, like:
# circup install font_raleway_medium_48
# circup install font_ostrich_sans_bold_48
# circup install font_league_gothic_italic_48
# circup install font font_fanwood_webfont_48
# circup install font_orbitron_light_webfont_48
# circup install font_league_gothic_regular_48
#
import time, math, random, gc, os
import board
import keypad
import displayio
import terminalio
from adafruit_display_text.bitmap_label import Label
from font_raleway_medium_48 import FONT as font_raleway_medium_48
from font_ostrich_sans_bold_48 import FONT as font_ostrich_sans_bold_48
from font_league_gothic_italic_48 import FONT as font_league_gothic_italic_48
from font_fanwood_webfont_48 import FONT as font_fanwood_webfont_48
from font_orbitron_light_webfont_48 import FONT as font_orbitron_light_webfont_48
from font_league_gothic_regular_48 import FONT as font_league_gothic_regular_48
myfonts = [font_raleway_medium_48,
font_ostrich_sans_bold_48,
font_league_gothic_italic_48,
font_fanwood_webfont_48,
font_orbitron_light_webfont_48,
font_league_gothic_regular_48]
font_size = 48
keys = keypad.Keys( (board.BUTTON0, board.BUTTON1), value_when_pressed=False, pull=True)
display = board.DISPLAY
display.auto_refresh = False
dw, dh = display.width, display.height
maingroup = displayio.Group()
display.root_group = maingroup
labels = displayio.Group()
maingroup.append(labels)
mycolors = (0x66ffff, 0x66ff33, 0x3333ff, 0xff33ff,
0xff3333, 0xffcc33, 0x66ff99, 0xdddddd)
y0 = 0
for i,f in enumerate(myfonts):
label = Label(font=f, text="Hello World!", x=5, y=y0+(font_size*i), background_tight=True)
labels.append(label)
ymax = font_size*len(myfonts)
yinc = -1
while True:
if key := keys.events.get():
print(key)
if key.key_number == 0 and key.pressed:
yinc = yinc + 1
if key.key_number == 1 and key.pressed:
yinc = yinc - 1
for l in labels:
l.y = l.y + yinc
if l.y < -font_size/2:
l.y = ymax
rc = mycolors[random.randint(0,len(mycolors)-1)]
print("color = %06x" % rc)
l.color = rc
st = time.monotonic()
display.refresh()
et = time.monotonic()
#print("dt millis %d" % ((et-st)*1000)) #, button0.value, button1.value)
#time.sleep(0.1)
# circuitpython_font_play_code.py -- playing with adafruit circuitpython-fonts package
# 8 Aug 2025 - @todbot / Tod Kurt
# developed on a Lilygo T-Display S3 w/ ST7789 display in paralleldisplaybus mode
# To use this, first install 'circup' and do what's described here https://github.com/adafruit/circuitpython-fonts/
# e.g.:
# circup bundle-add adafruit/circuitpython-fonts # You only need to do this once
# circup show | grep 48 | grep font # find fonts that are size 48
# circup install font_... # find a find you like and install it, the fonts I installed are:
# circup install font_raleway_medium_48
# circup install font_ostrich_sans_bold_48
# circup install font_league_gothic_italic_48
# circup install font_fanwood_webfont_48
# circup install font_orbitron_light_webfont_48
# circup install font_league_gothic_regular_48
# circup install adafruit_display_text
#
import time, math, gc, os
import board
import displayio
import terminalio
from adafruit_display_text.bitmap_label import Label
# look for installed fonts from "adafruit/circuitpython-fonts"
# that were installed with "circup install font_..."
# the font names have the pattern where the last part of their name is font size
font_size = 48
font_names = []
for filename in os.listdir('/lib'):
fnamel = filename.lower()
if (fnamel.startswith("font_") and fnamel.endswith(str(font_size)) and
not fnamel.startswith(".")):
font_names.append(filename)
print("found font_names:", font_names)
# now import those font package names as actual Python packages
# using a little import magic to dynamically load
myfonts = []
for name in font_names:
font = __import__(name).FONT
myfonts.append(font)
print("loaded myfonts:", myfonts)
display = board.DISPLAY
display.auto_refresh = False
dw, dh = display.width, display.height
maingroup = displayio.Group()
display.root_group = maingroup
labels = displayio.Group()
maingroup.append(labels)
y0 = 0
for i,f in enumerate(myfonts):
label = Label(font=f, text="Hello World!", x=5, y=y0+(font_size*i), background_tight=True)
labels.append(label)
ymax = font_size*len(myfonts)
display.refresh() # auto-refresh does not actually seem to be enabled
display.auto_refresh = False
while True:
for l in labels:
l.y = l.y - 1
if l.y < -font_size/2:
l.y = ymax
st = time.monotonic()
display.refresh()
et = time.monotonic()
print("dt millis %d" % ((et-st)*1000))
#time.sleep(0.1)
@todbot
Copy link
Author

todbot commented Aug 9, 2025

Video demo of the above

circuitpython_font_play.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment