Skip to content

Commit 983fd85

Browse files
committed
add updating label example
1 parent 2a7a154 commit 983fd85

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • CircuitPython_Display_Text/updating_text_example
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
This examples shows how to update your label with new text.
6+
"""
7+
import time
8+
import board
9+
import displayio
10+
import terminalio
11+
from adafruit_display_text import label
12+
13+
# built-in display
14+
display = board.DISPLAY
15+
16+
# Make the display context
17+
main_group = displayio.Group()
18+
display.show(main_group)
19+
20+
# create the label
21+
updating_label = label.Label(
22+
font=terminalio.FONT,
23+
text="Time Is:\n{}".format(time.monotonic()),
24+
scale=2
25+
)
26+
27+
# set label position on the display
28+
updating_label.anchor_point = (0, 0)
29+
updating_label.anchored_position = (20, 20)
30+
31+
# add label to group that is showing on display
32+
main_group.append(updating_label)
33+
34+
# Main loop
35+
while True:
36+
37+
# update text property to change the text showing on the display
38+
updating_label.text = "Time Is:\n{}".format(time.monotonic())
39+
40+
time.sleep(1)

0 commit comments

Comments
 (0)