Skip to content

Commit 62e7cdc

Browse files
committed
adding magtag example
1 parent aedb89c commit 62e7cdc

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

examples/display_text_magtag.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Basic display_text.label example script
3+
adapted for use on MagTag.
4+
"""
5+
import time
6+
import board
7+
import displayio
8+
import terminalio
9+
from adafruit_display_text import label
10+
11+
12+
13+
# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
14+
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
15+
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
16+
display = board.DISPLAY
17+
18+
# wait until we can draw
19+
time.sleep(display.time_to_refresh)
20+
21+
# main group to hold everything
22+
main_group = displayio.Group()
23+
24+
# white background. Scaled to save RAM
25+
bg_bitmap = displayio.Bitmap(display.width // 8, display.height // 8, 1)
26+
bg_palette = displayio.Palette(1)
27+
bg_palette[0] = 0xFFFFFF
28+
bg_sprite = displayio.TileGrid(bg_bitmap, x=0, y=0, pixel_shader=bg_palette)
29+
bg_group = displayio.Group(scale=8)
30+
bg_group.append(bg_sprite)
31+
main_group.append(bg_group)
32+
33+
# first example label
34+
TEXT = "Hello world"
35+
text_area = label.Label(
36+
terminalio.FONT,
37+
text=TEXT,
38+
color=0xFFFFFF,
39+
background_color=0x666666,
40+
padding_top=1,
41+
padding_bottom=3,
42+
padding_right=4,
43+
padding_left=4,
44+
)
45+
text_area.x = 10
46+
text_area.y = 14
47+
main_group.append(text_area)
48+
49+
# second example label
50+
another_text = label.Label(
51+
terminalio.FONT,
52+
scale=2,
53+
text="MagTag display_text\nexample",
54+
color=0x000000,
55+
background_color=0x999999,
56+
padding_top=1,
57+
padding_bottom=3,
58+
padding_right=4,
59+
padding_left=4,
60+
)
61+
# centered
62+
another_text.anchor_point = (0.5, 0.5)
63+
another_text.anchored_position = (display.width // 2, display.height // 2)
64+
main_group.append(another_text)
65+
66+
# show the main group and refresh.
67+
display.show(main_group)
68+
display.refresh()
69+
while True:
70+
pass

0 commit comments

Comments
 (0)