Simple Test

Ensure your device works with this simple test.

examples/display_text_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import terminalio
 6
 7from adafruit_display_text import label
 8
 9text = "Hello world"
10text_area = label.Label(terminalio.FONT, text=text)
11text_area.x = 10
12text_area.y = 10
13board.DISPLAY.root_group = text_area
14while True:
15    pass

Bitmap_label Simple Test

Simple test using bitmap_label to display text

examples/display_text_bitmap_label_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import terminalio
 6
 7from adafruit_display_text import bitmap_label
 8
 9text = "Hello world"
10text_area = bitmap_label.Label(terminalio.FONT, text=text)
11text_area.x = 10
12text_area.y = 10
13board.DISPLAY.root_group = text_area
14while True:
15    pass

ScrollingLabel Simple Test

Simple test using scrolling_label to display text

examples/display_text_scrolling_label.py
 1# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import terminalio
 6
 7from adafruit_display_text.scrolling_label import ScrollingLabel
 8
 9text = "Hello world CircuitPython scrolling label"
10my_scrolling_label = ScrollingLabel(terminalio.FONT, text=text, max_characters=20, animate_time=0.3)
11my_scrolling_label.x = 10
12my_scrolling_label.y = 10
13board.DISPLAY.root_group = my_scrolling_label
14while True:
15    my_scrolling_label.update()

OutlinedLabel Simple Test

Simple test using outlined_label to display text with a stroke outline

examples/display_text_outlined_label_simpletest.py
 1# SPDX-FileCopyrightText: 2023 Tim C
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import terminalio
 6
 7from adafruit_display_text import outlined_label
 8
 9if board.DISPLAY.width <= 150:
10    text = "Hello\nworld"
11else:
12    text = "Hello world"
13
14text_area = outlined_label.OutlinedLabel(
15    terminalio.FONT,
16    text=text,
17    color=0xFF00FF,
18    outline_color=0x00FF00,
19    outline_size=1,
20    padding_left=2,
21    padding_right=2,
22    padding_top=2,
23    padding_bottom=2,
24    scale=3,
25)
26text_area.anchor_point = (0, 0)
27text_area.anchored_position = (10, 10)
28board.DISPLAY.root_group = text_area
29while True:
30    pass

Label vs Bitmap_label Comparison

Example to compare Label and Bitmap_Label characteristics

examples/display_text_label_vs_bitmap_label_comparison.py
  1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
  2# SPDX-License-Identifier: MIT
  3
  4# Sample for comparing label and bitmap_label positioning with Builtin or loaded BDF fonts
  5
  6import gc
  7
  8import board
  9import displayio
 10import fourwire
 11import terminalio
 12from adafruit_bitmap_font import bitmap_font
 13
 14from adafruit_display_text import bitmap_label, label
 15
 16##########
 17# Use this Boolean variables to select which font style to use
 18##########
 19use_builtinfont = False  # Set True to use the terminalio.FONT BuiltinFont,
 20fontToUse = terminalio.FONT
 21# Set False to use a BDF loaded font, see "fontFiles" below
 22##########
 23
 24if not use_builtinfont:
 25    # load the fonts
 26    print("loading font...")
 27
 28    fontList = []
 29
 30    # Load some proportional fonts
 31    fontFile = "fonts/LeagueSpartan-Bold-16.bdf"
 32    fontToUse = bitmap_font.load_font(fontFile)
 33
 34# Set scaling factor for display text
 35my_scale = 1
 36
 37#  Setup the SPI display
 38if "DISPLAY" in dir(board):
 39    # use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
 40    # see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
 41    # https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
 42    display = board.DISPLAY
 43
 44else:
 45    # Setup the LCD display with driver
 46    # You may need to change this to match the display driver for the chipset
 47    # used on your display
 48    from adafruit_ili9341 import ILI9341
 49
 50    displayio.release_displays()
 51
 52    # setup the SPI bus
 53    spi = board.SPI()
 54    tft_cs = board.D9  # arbitrary, pin not used
 55    tft_dc = board.D10
 56    tft_backlight = board.D12
 57    tft_reset = board.D11
 58
 59    while not spi.try_lock():
 60        spi.configure(baudrate=32000000)
 61    spi.unlock()
 62
 63    display_bus = fourwire.FourWire(
 64        spi,
 65        command=tft_dc,
 66        chip_select=tft_cs,
 67        reset=tft_reset,
 68        baudrate=32000000,
 69        polarity=1,
 70        phase=1,
 71    )
 72
 73    # Number of pixels in the display
 74    DISPLAY_WIDTH = 320
 75    DISPLAY_HEIGHT = 240
 76
 77    # create the display
 78    display = ILI9341(
 79        display_bus,
 80        width=DISPLAY_WIDTH,
 81        height=DISPLAY_HEIGHT,
 82        rotation=180,  # The rotation can be adjusted to match your configuration.
 83        auto_refresh=True,
 84        native_frames_per_second=90,
 85    )
 86
 87    # reset the display to show nothing.
 88    display.root_group = None
 89
 90print("Display is started")
 91
 92preload_glyphs = True  # set this to True if you want to preload the font glyphs into memory
 93# preloading the glyphs will help speed up the rendering of text but will use more RAM
 94
 95if preload_glyphs and not use_builtinfont:
 96    # identify the glyphs to load into memory -> increases rendering speed
 97    glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-_,.:?!'\n "
 98
 99    print("loading glyphs...")
100    fontToUse.load_glyphs(glyphs)
101
102    print("Glyphs are loaded.")
103
104print("Fonts completed loading.")
105
106# create group
107
108long_string = "The purple snake\nbrings python fun\nto everyone."
109label2_padding = 10
110
111#####
112# Create the "bitmap_label.py" versions of the text labels.
113
114gc.collect()
115bitmap_label_start = gc.mem_free()
116
117bmap_label1 = bitmap_label.Label(
118    font=fontToUse,
119    text="bitmap_label",
120    color=0xFFFFFF,
121    background_color=0xFF0000,
122    padding_bottom=0,
123    padding_left=0,
124    padding_right=0,
125    padding_top=0,
126    background_tight=True,
127    line_spacing=1.25,
128    scale=my_scale,
129    anchor_point=(0.0, 0),
130    anchored_position=(10, 60),
131)
132
133bmap_label2 = bitmap_label.Label(
134    font=fontToUse,
135    text=long_string,
136    color=0x000000,
137    background_color=0xFFFF00,
138    padding_bottom=label2_padding,
139    padding_left=0,
140    padding_right=0,
141    padding_top=label2_padding,
142    background_tight=False,
143    line_spacing=1.25,
144    scale=my_scale,
145    anchor_point=(0.0, 0),
146    anchored_position=(10, 120),
147)
148
149gc.collect()
150bitmap_label_end = gc.mem_free()
151
152print(f"bitmap_label used: {bitmap_label_start - bitmap_label_end} memory")
153
154bmap_group = displayio.Group()  # Create a group for displaying
155bmap_group.append(bmap_label1)
156bmap_group.append(bmap_label2)
157
158
159#####
160# Create the "label.py" versions of the text labels.
161
162gc.collect()
163label_start = gc.mem_free()
164
165label1 = label.Label(
166    font=fontToUse,
167    text="label",
168    color=0xFFFFFF,
169    background_color=0xFF0000,
170    padding_bottom=0,
171    padding_left=0,
172    padding_right=0,
173    padding_top=0,
174    background_tight=True,
175    line_spacing=1.25,
176    scale=my_scale,
177    anchor_point=(1.0, 0),
178    anchored_position=(display.width - 10, 60),
179)
180
181label2 = label.Label(
182    font=fontToUse,
183    text=long_string,
184    color=0x000000,
185    background_color=0xFFFF00,
186    padding_bottom=label2_padding,
187    padding_left=0,
188    padding_right=0,
189    padding_top=label2_padding,
190    background_tight=False,
191    line_spacing=1.25,
192    scale=my_scale,
193    anchor_point=(1.0, 0),
194    anchored_position=(display.width - 10, 120),
195)
196
197gc.collect()
198label_end = gc.mem_free()
199
200print(f"label used: {label_start - label_end} memory")
201label_group = displayio.Group()  # Create a group for displaying
202label_group.append(label1)
203label_group.append(label2)
204
205
206print("***")
207
208main_group = displayio.Group()
209main_group.append(label_group)
210main_group.append(bmap_group)
211
212display.auto_refresh = True
213
214display.root_group = main_group
215while True:
216    pass

Background Color Example

Show the text backgrounds features

examples/display_text_background_color.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example shows the use color and background_color
 6"""
 7
 8import time
 9
10import board
11import terminalio
12
13from adafruit_display_text import label
14
15text = " Color Background Hello world"
16text_area = label.Label(terminalio.FONT, text=text, color=0x0000FF, background_color=0xFFAA00)
17text_area.x = 10
18text_area.y = 10
19
20print(f"background color is {text_area.background_color:06x}")
21
22board.DISPLAY.root_group = text_area
23
24time.sleep(2)
25text_area.background_color = 0xFF0000
26print(f"background color is {text_area.background_color:06x}")
27time.sleep(2)
28text_area.background_color = None
29print(f"background color is {text_area.background_color}")
30while True:
31    pass

Text Padding Example

Show the text padding features in all directions

examples/display_text_background_color.py
  1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
  2# SPDX-License-Identifier: MIT
  3
  4"""
  5This example shows the use color and background_color
  6"""
  7
  8import time
  9
 10import board
 11import displayio
 12import fourwire
 13from adafruit_bitmap_font import bitmap_font
 14
 15from adafruit_display_text import label
 16
 17#  Setup the SPI display
 18if "DISPLAY" in dir(board):
 19    # use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
 20    # see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
 21    # https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
 22    display = board.DISPLAY
 23
 24else:
 25    print("Starting external display")  # goes to serial only
 26    # Setup the LCD display with driver
 27    # You may need to change this to match the display driver for the chipset
 28    # used on your display
 29    from adafruit_ili9341 import ILI9341
 30
 31    # from adafruit_st7789 import ST7789
 32
 33    displayio.release_displays()
 34
 35    # setup the SPI bus
 36    spi = board.SPI()
 37    tft_cs = board.D9  # arbitrary, pin not used
 38    tft_dc = board.D10
 39    tft_backlight = board.D12
 40    tft_reset = board.D11
 41
 42    while not spi.try_lock():
 43        spi.configure(baudrate=32000000)
 44    spi.unlock()
 45
 46    display_bus = fourwire.FourWire(
 47        spi,
 48        command=tft_dc,
 49        chip_select=tft_cs,
 50        reset=tft_reset,
 51        baudrate=32000000,
 52        polarity=1,
 53        phase=1,
 54    )
 55
 56    # Number of pixels in the display
 57    DISPLAY_WIDTH = 320
 58    DISPLAY_HEIGHT = 240
 59
 60    # display = ST7789(display_bus, width=240, height=240, rotation=0, rowstart=80, colstart=0)
 61
 62    # create the display
 63    display = ILI9341(
 64        display_bus,
 65        width=DISPLAY_WIDTH,
 66        height=DISPLAY_HEIGHT,
 67        rotation=180,  # The rotation can be adjusted to match your configuration.
 68        auto_refresh=True,
 69        native_frames_per_second=90,
 70    )
 71
 72display.root_group = None
 73
 74# font=terminalio.FONT # this is the Builtin fixed dimension font
 75
 76font = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf")
 77
 78text = []
 79text.append("none")  # no ascenders or descenders
 80text.append("pop quops")  # only descenders
 81text.append("MONSTERs are tall")  # only ascenders
 82text.append("MONSTERs ate pop quops")  # both ascenders and descenders
 83text.append("MONSTER quops\nnewline quops")  # with newline
 84
 85display.auto_refresh = True
 86myGroup = displayio.Group()
 87display.root_group = myGroup
 88
 89text_area = []
 90myPadding = 4
 91
 92for i, thisText in enumerate(text):
 93    text_area.append(
 94        label.Label(
 95            font,
 96            text=thisText,
 97            color=0xFFFFFF,
 98            background_color=None,
 99            background_tight=False,
100            padding_top=myPadding,
101            padding_bottom=myPadding,
102            padding_left=myPadding,
103            padding_right=myPadding,
104        )
105    )
106
107    this_x = 10
108    this_y = 10 + i * 40
109    text_area[i].x = 10
110    text_area[i].y = 3 + i * 50
111    text_area[i].anchor_point = (0, 0)
112    text_area[i].anchored_position = (this_x, this_y)
113    myGroup.append(text_area[i])
114
115print(f"background color is {text_area[0].background_color}")
116
117
118while True:
119    time.sleep(2)
120    text_area[0].text = "text"  # change some text in an existing text box
121    # Note: changed text must fit within existing number of characters
122    # when the Label was created
123
124    for area in text_area:
125        area.background_color = 0xFF0000
126    print(f"background color is {text_area[0].background_color:06x}")
127    time.sleep(2)
128    for area in text_area:
129        area.background_color = 0x000088
130    print(f"background color is {text_area[0].background_color:06x}")
131    time.sleep(2)
132    for area in text_area:
133        area.background_color = 0x00FF00
134    print(f"background color is {text_area[0].background_color:06x}")
135    time.sleep(2)
136    for area in text_area:
137        area.background_color = 0xFF0000
138    print(f"background color is {text_area[0].background_color:06x}")
139    time.sleep(2)
140    for area in text_area:
141        area.background_color = None
142    print(f"background color is {text_area[0].background_color}")

Anchored Position

Anchored position use illustration

examples/display_text_anchored_position.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This examples shows the use of anchor_point and anchored_position.
 6"""
 7
 8import board
 9import displayio
10import terminalio
11
12from adafruit_display_text import label
13
14DISPLAY_WIDTH = 320
15DISPLAY_HEIGHT = 240
16TEXT = "Hello"
17
18text_area_top_left = label.Label(terminalio.FONT, text=TEXT)
19text_area_top_left.anchor_point = (0.0, 0.0)
20text_area_top_left.anchored_position = (0, 0)
21
22text_area_top_middle = label.Label(terminalio.FONT, text=TEXT)
23text_area_top_middle.anchor_point = (0.5, 0.0)
24text_area_top_middle.anchored_position = (DISPLAY_WIDTH / 2, 0)
25
26text_area_top_right = label.Label(terminalio.FONT, text=TEXT)
27text_area_top_right.anchor_point = (1.0, 0.0)
28text_area_top_right.anchored_position = (DISPLAY_WIDTH, 0)
29
30text_area_middle_left = label.Label(terminalio.FONT, text=TEXT)
31text_area_middle_left.anchor_point = (0.0, 0.5)
32text_area_middle_left.anchored_position = (0, DISPLAY_HEIGHT / 2)
33
34text_area_middle_middle = label.Label(terminalio.FONT, text=TEXT)
35text_area_middle_middle.anchor_point = (0.5, 0.5)
36text_area_middle_middle.anchored_position = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2)
37
38text_area_middle_right = label.Label(terminalio.FONT, text=TEXT)
39text_area_middle_right.anchor_point = (1.0, 0.5)
40text_area_middle_right.anchored_position = (DISPLAY_WIDTH, DISPLAY_HEIGHT / 2)
41
42text_area_bottom_left = label.Label(terminalio.FONT, text=TEXT)
43text_area_bottom_left.anchor_point = (0.0, 1.0)
44text_area_bottom_left.anchored_position = (0, DISPLAY_HEIGHT)
45
46text_area_bottom_middle = label.Label(terminalio.FONT, text=TEXT)
47text_area_bottom_middle.anchor_point = (0.5, 1.0)
48text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT)
49
50text_area_bottom_right = label.Label(terminalio.FONT, text=TEXT)
51text_area_bottom_right.anchor_point = (1.0, 1.0)
52text_area_bottom_right.anchored_position = (DISPLAY_WIDTH, DISPLAY_HEIGHT)
53
54text_group = displayio.Group()
55text_group.append(text_area_top_middle)
56text_group.append(text_area_top_left)
57text_group.append(text_area_top_right)
58text_group.append(text_area_middle_middle)
59text_group.append(text_area_middle_left)
60text_group.append(text_area_middle_right)
61text_group.append(text_area_bottom_middle)
62text_group.append(text_area_bottom_left)
63text_group.append(text_area_bottom_right)
64
65board.DISPLAY.root_group = text_group
66
67while True:
68    pass

Textarea Boundingbox

Boundingbox demonstration

examples/display_text_textarea_boundingbox.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import os
 5
 6import board
 7import displayio
 8from adafruit_bitmap_font import bitmap_font
 9
10from adafruit_display_text.label import Label
11
12# the current working directory (where this file is)
13cwd = ("/" + __file__).rsplit("/", 1)[0]
14fonts = [
15    file
16    for file in os.listdir(cwd + "/fonts/")
17    if (file.endswith(".bdf") and not file.startswith("._"))
18]
19for i, filename in enumerate(fonts):
20    fonts[i] = cwd + "/fonts/" + filename
21print(fonts)
22
23##########################################################################
24THE_FONT = fonts[0]
25DISPLAY_STRING = "A multi-line-\nexample of\n  font bounding!"
26WRAP_CHARS = 40
27
28##########################################################################
29# Make the display context
30splash = displayio.Group()
31board.DISPLAY.root_group = splash
32
33# Make a background color fill
34color_bitmap = displayio.Bitmap(320, 240, 1)
35color_palette = displayio.Palette(1)
36color_palette[0] = 0xFFFFFF
37bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
38splash.append(bg_sprite)
39
40# Load the font
41font = bitmap_font.load_font(THE_FONT)
42font.load_glyphs(DISPLAY_STRING.encode("utf-8"))
43
44print(DISPLAY_STRING)
45
46text = Label(font, text=DISPLAY_STRING)
47text.x = 20
48text.y = 100
49text.color = 0x0
50
51# Make a background color fill
52dims = text.bounding_box
53print(dims)
54textbg_bitmap = displayio.Bitmap(dims[2], dims[3], 1)
55textbg_palette = displayio.Palette(1)
56textbg_palette[0] = 0xFF0000
57textbg_sprite = displayio.TileGrid(
58    textbg_bitmap, pixel_shader=textbg_palette, x=text.x + dims[0], y=text.y + dims[1]
59)
60splash.append(textbg_sprite)
61splash.append(text)
62try:
63    board.DISPLAY.refresh(target_frames_per_second=60)
64except AttributeError:
65    board.DISPLAY.refresh_soon()
66    board.DISPLAY.wait_for_frame()
67
68
69while True:
70    pass

Align Baseline Example

Demonstrate how to align different labels to a common horizontal line

examples/display_text_label_align_baseline_comparison.py
 1# SPDX-FileCopyrightText: 2021 Jose David Montoya for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example shows the use of base_alignment parameter.
 6"""
 7
 8import board
 9import displayio
10from adafruit_bitmap_font import bitmap_font
11
12from adafruit_display_text import label
13
14display = board.DISPLAY
15
16# Font definition. You can choose any two fonts available in your system
17MEDIUM_FONT = bitmap_font.load_font("LeagueSpartan-Bold-16.bdf")
18BIG_FONT = bitmap_font.load_font("LibreBodoniv2002-Bold-27.bdf")
19
20TEXT_RIGHT = "MG"
21TEXT_LEFT = "32.47"
22
23main_group = displayio.Group()
24
25# Create labels
26# Base Alignment parameter False
27left_text = label.Label(
28    BIG_FONT,
29    text=TEXT_LEFT,
30    color=0x000000,
31    background_color=0x999999,
32    x=10,
33    y=50,
34    base_alignment=False,
35)
36main_group.append(left_text)
37
38right_text = label.Label(
39    MEDIUM_FONT,
40    text=TEXT_RIGHT,
41    color=0x000000,
42    background_color=0x999999,
43    x=90,
44    y=50,
45    base_alignment=False,
46)
47main_group.append(right_text)
48
49# Base Alignment parameter True
50left_text_aligned = label.Label(
51    BIG_FONT,
52    text=TEXT_LEFT,
53    color=0x000000,
54    background_color=0x999999,
55    x=10,
56    y=100,
57    base_alignment=True,
58)
59main_group.append(left_text_aligned)
60
61right_text_aligned = label.Label(
62    MEDIUM_FONT,
63    text=TEXT_RIGHT,
64    color=0x000000,
65    background_color=0x999999,
66    x=90,
67    y=100,
68    base_alignment=True,
69)
70
71main_group.append(right_text_aligned)
72display.root_group = main_group
73
74while True:
75    pass

Magtag Example

Uses the MAGTAG to display some text

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

MatrixPortal Example

Uses the MatrixPortal to display some text

examples/display_text_matrixportal.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example shows how to create a display_text label and show it
 6with a Matrix Portal
 7
 8Requires:
 9adafruit_matrixportal - https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal
10
11Copy it from the current libraries bundle into the lib folder on your device.
12"""
13
14import terminalio
15from adafruit_matrixportal.matrix import Matrix
16
17from adafruit_display_text import label
18
19matrix = Matrix()
20display = matrix.display
21
22text = "Hello\nworld"
23text_area = label.Label(terminalio.FONT, text=text)
24text_area.x = 1
25text_area.y = 4
26display.root_group = text_area
27while True:
28    pass

PyPortal Example

Uses the Pyportal to display some text

examples/display_text_pyportal.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example show the use of the backlight as well as using labels to simulate
 6a terminal using a font on the PyPortal
 7"""
 8
 9import os
10import time
11
12import board
13import displayio
14from adafruit_bitmap_font import bitmap_font
15
16from adafruit_display_text.label import Label
17
18FONT_DIR = "/fonts/"
19fonts = list(filter(lambda x: x.endswith("bdf") and not x.startswith("."), os.listdir(FONT_DIR)))
20fonts = [bitmap_font.load_font(FONT_DIR + x) for x in fonts]
21if len(fonts) == 0:
22    print(f"No fonts found in '{FONT_DIR}'")
23
24print("fade up")
25# Fade up the backlight
26for b in range(100):
27    board.DISPLAY.brightness = b / 100
28    time.sleep(0.01)  # default (0.01)
29
30demos = ["CircuitPython = Code + Community", "accents - üàêùéáçãÍóí", "others - αψ◌"]
31
32splash = displayio.Group()
33board.DISPLAY.root_group = splash
34max_y = 0
35y = 0
36for demo_text in demos:
37    for font in fonts:
38        if y >= board.DISPLAY.height:
39            y = 0
40            while len(splash):
41                splash.pop()
42        print(f"Font load {font.name}")
43        area = Label(font, text=demo_text, anchor_point=(0, 0), anchored_position=(0, y))
44        splash.append(area)
45
46        y += area.height
47
48        # Wait for the image to load.
49        try:
50            board.DISPLAY.refresh(target_frames_per_second=60)
51        except AttributeError:
52            board.DISPLAY.wait_for_frame()
53
54# Wait for 1 minute (60 seconds)
55time.sleep(60)
56
57# Fade down the backlight
58for b in range(100, -1, -1):
59    board.DISPLAY.brightness = b / 100
60    time.sleep(0.01)  # default (0.01)
61
62print("fade down")
63
64time.sleep(10)

Wraptest Example

Illustrates the wraptest feature

examples/display_text_wraptest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example illustrates how to use the wrap_text_to_lines
 6helper function.
 7"""
 8
 9import board
10import terminalio
11
12from adafruit_display_text import label, wrap_text_to_lines
13
14# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
15# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
16# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
17display = board.DISPLAY
18
19text = (
20    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
21    "sed do eiusmod tempor incididunt ut labore et dolore magna "
22    "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
23    "ullamco laboris nisi ut aliquip ex ea commodo consequat."
24)
25text = "\n".join(wrap_text_to_lines(text, 28))
26text_area = label.Label(terminalio.FONT, text=text)
27text_area.x = 10
28text_area.y = 10
29display.root_group = text_area
30while True:
31    pass

Wrap Pixel Test

Wrap Pixel Test

examples/display_text_wrap_pixels_test.py
 1# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4"""
 5Test the wrap_text_to_pixels function. Try changing WRAP_WIDTH or text
 6and observe the results. The red bar represents the full size of
 7WRAP_WIDTH.
 8"""
 9
10import board
11import displayio
12import terminalio
13
14from adafruit_display_text import label, wrap_text_to_pixels
15
16WRAP_WIDTH = 140
17text = (
18    "CircuitPython is a programming language designed to simplify experimenting "
19    "and learning to code on low-cost microcontroller boards. "
20)
21
22# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
23# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
24# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
25display = board.DISPLAY
26
27# Make the display context
28main_group = displayio.Group()
29display.root_group = main_group
30
31font = terminalio.FONT
32
33print(text)
34print(display.width)
35
36text_area = label.Label(
37    font,
38    text="\n".join(wrap_text_to_pixels(text, WRAP_WIDTH, font)),
39    background_color=0x0000DD,
40)
41
42text_area.anchor_point = (0, 0)
43text_area.anchored_position = (0, 0)
44
45main_group.append(text_area)
46
47# Create a bitmap with two colors
48size_checker = displayio.Bitmap(WRAP_WIDTH, 10, 2)
49# Create a two color palette
50palette = displayio.Palette(2)
51palette[0] = 0x0000DD
52palette[1] = 0xDD0000
53
54# Create a TileGrid using the Bitmap and Palette
55tile_grid = displayio.TileGrid(size_checker, pixel_shader=palette)
56
57tile_grid.y = text_area.bounding_box[1] + text_area.bounding_box[3] + 10
58
59size_checker.fill(1)
60
61main_group.append(tile_grid)
62
63while True:
64    pass

Library Features Example

This examples shows the label and bitmap_label capabilities and features

examples/display_text_advance_example.py
  1# SPDX-FileCopyrightText: 2021 Jose David M.
  2#
  3# SPDX-License-Identifier: MIT
  4#############################
  5"""
  6This is an advanced demonstration of the display_text library capabilities
  7"""
  8
  9import time
 10
 11import board
 12import displayio
 13import fontio
 14import terminalio
 15from adafruit_bitmap_font import bitmap_font
 16
 17from adafruit_display_text import bitmap_label, label
 18
 19display = board.DISPLAY
 20main_group = displayio.Group()
 21MEDIUM_FONT = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf")
 22BIG_FONT = bitmap_font.load_font("fonts/LibreBodoniv2002-Bold-27.bdf")
 23TIME_PAUSE = 2
 24
 25bitmap = displayio.Bitmap(4, display.width, 2)
 26palette = displayio.Palette(2)
 27palette[0] = 0x004400
 28palette[1] = 0x00FFFF
 29horizontal_line = displayio.TileGrid(bitmap, pixel_shader=palette, x=155, y=0)
 30main_group.append(horizontal_line)
 31
 32bitmap = displayio.Bitmap(display.width, 4, 2)
 33vertical_line = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=110)
 34main_group.append(vertical_line)
 35
 36# Tests
 37text_area = label.Label(terminalio.FONT, text="Circuit Python")
 38main_group.append(text_area)
 39display.root_group = main_group
 40time.sleep(TIME_PAUSE)
 41
 42# Testing position setter
 43text_area.x = 10
 44text_area.y = 10
 45display.root_group = main_group
 46time.sleep(TIME_PAUSE)
 47
 48# Testing creating label with initial position
 49text_area.text = "Testing initiating without text"
 50try:
 51    text_middle = label.Label(terminalio.FONT)
 52except SyntaxError:
 53    print("Fail setting-up label without text")
 54    warning_text = label.Label(
 55        BIG_FONT,
 56        text="Test Fail",
 57        x=display.width // 2,
 58        y=display.height // 4,
 59        background_color=0x004499,
 60    )
 61    main_group.append(warning_text)
 62display.root_group = main_group
 63time.sleep(TIME_PAUSE)
 64
 65text_area.text = "Testing Position"
 66text_middle = label.Label(
 67    terminalio.FONT, text="Circuit", x=display.width // 2, y=display.height // 2
 68)
 69main_group.append(text_middle)
 70display.root_group = main_group
 71time.sleep(TIME_PAUSE)
 72
 73# Testing Text Setter
 74text_area.text = "Testing Changing Text"
 75text_middle.text = "Python"
 76display.root_group = main_group
 77time.sleep(TIME_PAUSE)
 78
 79# Testing a and y getter and setter
 80text_area.text = "Testing Changing Position"
 81text_middle.x = text_middle.x - 50
 82text_middle.y = text_middle.y - 50
 83display.root_group = main_group
 84time.sleep(TIME_PAUSE)
 85
 86# Testing font Getter and setter
 87text_area.text = "Testing Changing FONT"
 88if isinstance(text_middle.font, fontio.BuiltinFont):
 89    text_middle.font = MEDIUM_FONT
 90display.root_group = main_group
 91time.sleep(TIME_PAUSE)
 92
 93# Once this working we create another label with all the initial specs
 94main_group.pop()
 95
 96# Testing Color
 97text_area.text = "Testing Color"
 98text_initial_specs = label.Label(
 99    MEDIUM_FONT,
100    text="Circuit Python",
101    x=display.width // 2,
102    y=display.height // 2,
103)
104main_group.append(text_initial_specs)
105display.root_group = main_group
106time.sleep(TIME_PAUSE)
107
108text_initial_specs.color = 0x004400
109display.root_group = main_group
110time.sleep(TIME_PAUSE)
111main_group.pop()
112
113# Testing Background Color
114text_area.text = "Testing Background Color"
115text_initial_specs = label.Label(
116    MEDIUM_FONT,
117    text="CircuitPython",
118    x=display.width // 2,
119    y=display.height // 2,
120    color=0xFFFFFF,
121)
122main_group.append(text_initial_specs)
123display.root_group = main_group
124time.sleep(TIME_PAUSE)
125
126text_initial_specs.background_color = 0x990099
127display.root_group = main_group
128time.sleep(TIME_PAUSE)
129main_group.pop()
130
131# Testing Background Color
132text_area.text = "Testing Background Tight"
133text_initial_specs = label.Label(
134    BIG_FONT,
135    text="aaaaq~",
136    x=0,
137    y=display.height // 2,
138    color=0xFFFFFF,
139    background_color=0x990099,
140    background_tight=True,
141)
142main_group.append(text_initial_specs)
143text_initial_specs = label.Label(
144    BIG_FONT,
145    text="aaaaq~",
146    x=90,
147    y=display.height // 2,
148    color=0xFFFFFF,
149    background_color=0x990099,
150    background_tight=False,
151)
152main_group.append(text_initial_specs)
153display.root_group = main_group
154time.sleep(TIME_PAUSE)
155main_group.pop()
156main_group.pop()
157
158# Testing Padding
159text_area.text = "Testing Padding"
160text_initial_specs = label.Label(
161    BIG_FONT,
162    text="CircuitPython",
163    x=display.width // 4,
164    y=display.height // 2,
165    color=0xFFFFFF,
166    background_color=0x990099,
167    padding_right=10,
168    padding_top=10,
169    padding_bottom=10,
170    padding_left=10,
171)
172main_group.append(text_initial_specs)
173display.root_group = main_group
174time.sleep(TIME_PAUSE)
175main_group.pop()
176
177# Testing Anchor Point/ Anchored Position
178text_area.text = "Testing Anchor Point/Anchored Position"
179text_initial_specs = label.Label(
180    MEDIUM_FONT,
181    text="CircuitPython",
182    x=display.width // 2,
183    y=display.height // 2,
184    color=0xFFFFFF,
185    background_color=0x990099,
186    padding_right=10,
187    padding_top=10,
188    padding_bottom=10,
189    padding_left=10,
190)
191main_group.append(text_initial_specs)
192display.root_group = main_group
193time.sleep(TIME_PAUSE)
194
195try:
196    text_initial_specs.anchored_position = (100, 100)
197    text_initial_specs.anchor_point = (0.5, 0.5)
198
199except TypeError:
200    print("Test is failing here")
201    main_group.pop()
202    warning_text = label.Label(
203        BIG_FONT,
204        text="Test Fail",
205        x=display.width // 2,
206        y=display.height // 4,
207        background_color=0x004499,
208    )
209    main_group.append(warning_text)
210    time.sleep(TIME_PAUSE)
211    display.root_group = main_group
212
213main_group.pop()
214
215# Testing Scale
216text_area.text = "Testing Scale"
217text_initial_specs = label.Label(
218    MEDIUM_FONT,
219    text="CircuitPython",
220    x=display.width // 2,
221    y=display.height // 2,
222    color=0xFFFFFF,
223    background_color=0x990099,
224    padding_right=10,
225    padding_top=10,
226    padding_bottom=10,
227    padding_left=10,
228    anchored_position=(display.width // 2, display.height // 2),
229    anchor_point=(0.5, 0.5),
230)
231main_group.append(text_initial_specs)
232display.root_group = main_group
233time.sleep(TIME_PAUSE)
234
235text_initial_specs.scale = 2
236display.root_group = main_group
237time.sleep(TIME_PAUSE)
238main_group.pop()
239
240# Testing Base Alignment
241text_area.text = "Testing Base Alignment"
242text_initial_specs = label.Label(
243    MEDIUM_FONT,
244    text="python",
245    x=display.width // 2,
246    y=display.height // 2,
247    color=0xFFFFFF,
248    background_color=0x990099,
249    base_alignment=True,
250)
251main_group.append(text_initial_specs)
252text_initial_specs = label.Label(
253    BIG_FONT,
254    text="circuit",
255    x=display.width // 2 - 100,
256    y=display.height // 2,
257    color=0xFFFFFF,
258    background_color=0x990099,
259    base_alignment=True,
260)
261main_group.append(text_initial_specs)
262display.root_group = main_group
263time.sleep(TIME_PAUSE)
264main_group.pop()
265main_group.pop()
266
267# Testing Direction
268text_area.text = "Testing Direction-UPR"
269text_initial_specs = label.Label(
270    MEDIUM_FONT,
271    text="CircuitPython",
272    x=display.width // 2,
273    y=display.height // 2,
274    color=0xFFFFFF,
275    background_color=0x990099,
276    padding_right=10,
277    padding_top=10,
278    padding_bottom=10,
279    padding_left=10,
280    anchored_position=(display.width // 2, display.height // 2),
281    anchor_point=(0.5, 0.5),
282    label_direction="UPR",
283)
284main_group.append(text_initial_specs)
285display.root_group = main_group
286time.sleep(TIME_PAUSE)
287main_group.pop()
288
289text_area.text = "Testing Direction-DWR"
290text_initial_specs = label.Label(
291    MEDIUM_FONT,
292    text="CircuitPython",
293    x=display.width // 2,
294    y=display.height // 2,
295    color=0xFFFFFF,
296    background_color=0x990099,
297    padding_right=10,
298    padding_top=10,
299    padding_bottom=10,
300    padding_left=10,
301    anchored_position=(display.width // 2, display.height // 2),
302    anchor_point=(0.5, 0.5),
303    label_direction="DWR",
304)
305main_group.append(text_initial_specs)
306display.root_group = main_group
307time.sleep(TIME_PAUSE)
308main_group.pop()
309
310text_area.text = "Testing Direction-TTB"
311text_initial_specs = label.Label(
312    MEDIUM_FONT,
313    text="CircuitPython",
314    x=display.width // 2,
315    y=display.height // 2,
316    color=0xFFFFFF,
317    background_color=0x990099,
318    padding_right=10,
319    padding_top=10,
320    padding_bottom=10,
321    padding_left=10,
322    anchored_position=(display.width // 2, display.height // 2),
323    anchor_point=(0.5, 0.5),
324    label_direction="TTB",
325)
326main_group.append(text_initial_specs)
327display.root_group = main_group
328time.sleep(TIME_PAUSE)
329main_group.pop()
330
331text_area.text = "Testing Direction-RTL"
332text_initial_specs = label.Label(
333    MEDIUM_FONT,
334    text="CircuitPython",
335    x=display.width // 2,
336    y=display.height // 2,
337    color=0xFFFFFF,
338    background_color=0x990099,
339    padding_right=10,
340    padding_top=10,
341    padding_bottom=10,
342    padding_left=10,
343    anchored_position=(display.width // 2, display.height // 2),
344    anchor_point=(0.5, 0.5),
345    label_direction="RTL",
346)
347main_group.append(text_initial_specs)
348display.root_group = main_group
349time.sleep(TIME_PAUSE)
350main_group.pop()
351
352main_group.pop()
353
354# Testing creating label with initial position
355display.root_group = main_group
356time.sleep(TIME_PAUSE)
357text_area = bitmap_label.Label(terminalio.FONT, text="Circuit Python")
358main_group.append(text_area)
359display.root_group = main_group
360time.sleep(TIME_PAUSE)
361# Testing position setter
362text_area.x = 10
363text_area.y = 10
364display.root_group = main_group
365time.sleep(TIME_PAUSE)
366text_area.text = "Testing initiating without text"
367try:
368    text_middle = label.Label(terminalio.FONT)
369except TypeError:
370    print("Fail setting-up label without text")
371    warning_text = label.Label(
372        BIG_FONT,
373        text="Test Fail",
374        x=display.width // 2,
375        y=display.height // 4,
376        background_color=0x004499,
377    )
378    main_group.append(warning_text)
379
380# Testing creating label with initial position
381text_area.text = "Testing Position"
382text_middle = bitmap_label.Label(
383    terminalio.FONT, text="Circuit", x=display.width // 2, y=display.height // 2
384)
385main_group.append(text_middle)
386display.root_group = main_group
387time.sleep(TIME_PAUSE)
388
389# Testing Text Setter
390text_area.text = "Testing Changing Text"
391text_middle.text = "Python"
392display.root_group = main_group
393time.sleep(TIME_PAUSE)
394
395# Testing a and y getter and setter
396text_area.text = "Testing Changing Position"
397text_middle.x = text_middle.x - 50
398text_middle.y = text_middle.y - 50
399display.root_group = main_group
400time.sleep(TIME_PAUSE)
401
402# Testing font Getter and setter
403text_area.text = "Testing Changing FONT"
404if isinstance(text_middle.font, fontio.BuiltinFont):
405    print("Font was BuiltinFont")
406    text_middle.font = MEDIUM_FONT
407display.root_group = main_group
408time.sleep(TIME_PAUSE)
409
410# Once this working we create another label with all the initial specs
411main_group.pop()
412
413# Testing Color
414text_area.text = "Testing Color"
415text_initial_specs = bitmap_label.Label(
416    MEDIUM_FONT,
417    text="Circuit Python",
418    x=display.width // 2,
419    y=display.height // 2,
420)
421main_group.append(text_initial_specs)
422display.root_group = main_group
423time.sleep(TIME_PAUSE)
424
425text_initial_specs.color = 0x004400
426display.root_group = main_group
427time.sleep(TIME_PAUSE)
428main_group.pop()
429
430# Testing Background Color
431text_area.text = "Testing Background Color"
432text_initial_specs = bitmap_label.Label(
433    MEDIUM_FONT,
434    text="CircuitPython",
435    x=display.width // 2,
436    y=display.height // 2,
437    color=0xFFFFFF,
438)
439main_group.append(text_initial_specs)
440display.root_group = main_group
441time.sleep(TIME_PAUSE)
442
443text_initial_specs.background_color = 0x990099
444display.root_group = main_group
445time.sleep(TIME_PAUSE)
446main_group.pop()
447
448# Testing Background Color
449text_area.text = "Testing Background Tight"
450text_initial_specs = bitmap_label.Label(
451    BIG_FONT,
452    text="aaaaq~",
453    x=0,
454    y=display.height // 2,
455    color=0xFFFFFF,
456    background_color=0x990099,
457    background_tight=True,
458)
459main_group.append(text_initial_specs)
460text_initial_specs = bitmap_label.Label(
461    BIG_FONT,
462    text="aaaaq~",
463    x=90,
464    y=display.height // 2,
465    color=0xFFFFFF,
466    background_color=0x990099,
467    background_tight=False,
468)
469main_group.append(text_initial_specs)
470display.root_group = main_group
471time.sleep(TIME_PAUSE)
472main_group.pop()
473main_group.pop()
474
475# Testing Padding
476text_area.text = "Testing Padding"
477text_initial_specs = bitmap_label.Label(
478    BIG_FONT,
479    text="CircuitPython",
480    x=display.width // 4,
481    y=display.height // 2,
482    color=0xFFFFFF,
483    background_color=0x990099,
484    padding_right=10,
485    padding_top=10,
486    padding_bottom=10,
487    padding_left=10,
488)
489main_group.append(text_initial_specs)
490display.root_group = main_group
491time.sleep(TIME_PAUSE)
492main_group.pop()
493
494# Testing Anchor Point/ Anchored Position
495text_area.text = "Testing Anchor Point/Anchored Position"
496text_initial_specs = bitmap_label.Label(
497    MEDIUM_FONT,
498    text="CircuitPython",
499    x=display.width // 2,
500    y=display.height // 2,
501    color=0xFFFFFF,
502    background_color=0x990099,
503    padding_right=10,
504    padding_top=10,
505    padding_bottom=10,
506    padding_left=10,
507)
508main_group.append(text_initial_specs)
509display.root_group = main_group
510time.sleep(TIME_PAUSE)
511
512try:
513    text_initial_specs.anchored_position = (100, 100)
514    text_initial_specs.anchor_point = (0.5, 0.5)
515
516except TypeError:
517    print("Test is failing here")
518    main_group.pop()
519    warning_text = bitmap_label.Label(
520        BIG_FONT,
521        text="Test Fail",
522        x=display.width // 2,
523        y=display.height // 4,
524        background_color=0x004499,
525    )
526    main_group.append(warning_text)
527    time.sleep(TIME_PAUSE)
528    display.root_group = main_group
529
530main_group.pop()
531
532# Testing Scale
533text_area.text = "Testing Scale"
534text_initial_specs = bitmap_label.Label(
535    MEDIUM_FONT,
536    text="CircuitPython",
537    x=display.width // 2,
538    y=display.height // 2,
539    color=0xFFFFFF,
540    background_color=0x990099,
541    padding_right=10,
542    padding_top=10,
543    padding_bottom=10,
544    padding_left=10,
545    anchored_position=(display.width // 2, display.height // 2),
546    anchor_point=(0.5, 0.5),
547)
548main_group.append(text_initial_specs)
549display.root_group = main_group
550time.sleep(TIME_PAUSE)
551
552text_initial_specs.scale = 2
553display.root_group = main_group
554time.sleep(TIME_PAUSE)
555main_group.pop()
556
557# Testing Base Alignment
558text_area.text = "Testing Base Alignment"
559text_initial_specs = bitmap_label.Label(
560    MEDIUM_FONT,
561    text="python",
562    x=display.width // 2,
563    y=display.height // 2,
564    color=0xFFFFFF,
565    background_color=0x990099,
566    base_alignment=True,
567)
568main_group.append(text_initial_specs)
569text_initial_specs = bitmap_label.Label(
570    BIG_FONT,
571    text="circuit",
572    x=display.width // 2 - 100,
573    y=display.height // 2,
574    color=0xFFFFFF,
575    background_color=0x990099,
576    base_alignment=True,
577)
578main_group.append(text_initial_specs)
579display.root_group = main_group
580time.sleep(TIME_PAUSE)
581main_group.pop()
582main_group.pop()
583
584# Testing Direction
585text_area.text = "Testing Direction-UPR"
586text_initial_specs = bitmap_label.Label(
587    MEDIUM_FONT,
588    text="CircuitPython",
589    x=display.width // 2,
590    y=display.height // 2,
591    color=0xFFFFFF,
592    background_color=0x990099,
593    padding_right=10,
594    padding_top=10,
595    padding_bottom=10,
596    padding_left=10,
597    anchored_position=(display.width // 2, display.height // 2),
598    anchor_point=(0.5, 0.5),
599    label_direction="UPR",
600)
601main_group.append(text_initial_specs)
602display.root_group = main_group
603time.sleep(TIME_PAUSE)
604main_group.pop()
605
606text_area.text = "Testing Direction-DWR"
607text_initial_specs = bitmap_label.Label(
608    MEDIUM_FONT,
609    text="CircuitPython",
610    x=display.width // 2,
611    y=display.height // 2,
612    color=0xFFFFFF,
613    background_color=0x990099,
614    padding_right=10,
615    padding_top=10,
616    padding_bottom=10,
617    padding_left=10,
618    anchored_position=(display.width // 2, display.height // 2),
619    anchor_point=(0.5, 0.5),
620    label_direction="DWR",
621)
622main_group.append(text_initial_specs)
623display.root_group = main_group
624time.sleep(TIME_PAUSE)
625main_group.pop()
626
627text_area.text = "Testing Direction-UPD"
628text_initial_specs = bitmap_label.Label(
629    MEDIUM_FONT,
630    text="CircuitPython",
631    x=display.width // 2,
632    y=display.height // 2,
633    color=0xFFFFFF,
634    background_color=0x990099,
635    padding_right=10,
636    padding_top=10,
637    padding_bottom=10,
638    padding_left=10,
639    anchored_position=(display.width // 2, display.height // 2),
640    anchor_point=(0.5, 0.5),
641    label_direction="UPD",
642)
643main_group.append(text_initial_specs)
644display.root_group = main_group
645time.sleep(TIME_PAUSE)
646main_group.pop()
647
648text_area.text = "Testing Direction-RTL"
649text_initial_specs = bitmap_label.Label(
650    MEDIUM_FONT,
651    text="CircuitPython",
652    x=display.width // 2,
653    y=display.height // 2,
654    color=0xFFFFFF,
655    background_color=0x990099,
656    padding_right=10,
657    padding_top=10,
658    padding_bottom=10,
659    padding_left=10,
660    anchored_position=(display.width // 2, display.height // 2),
661    anchor_point=(0.5, 0.5),
662    label_direction="RTL",
663)
664main_group.append(text_initial_specs)
665display.root_group = main_group
666time.sleep(TIME_PAUSE)
667main_group.pop()
668
669text_area.text = "Finished"
670print("Tests finished")