From 983fd850afb6836cf204d8ede34436163444df6d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 5 Dec 2021 16:12:10 -0600 Subject: [PATCH 1/2] add updating label example --- .../updating_text_example/code.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 CircuitPython_Display_Text/updating_text_example/code.py diff --git a/CircuitPython_Display_Text/updating_text_example/code.py b/CircuitPython_Display_Text/updating_text_example/code.py new file mode 100644 index 000000000..eef238ebc --- /dev/null +++ b/CircuitPython_Display_Text/updating_text_example/code.py @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT +""" +This examples shows how to update your label with new text. +""" +import time +import board +import displayio +import terminalio +from adafruit_display_text import label + +# built-in display +display = board.DISPLAY + +# Make the display context +main_group = displayio.Group() +display.show(main_group) + +# create the label +updating_label = label.Label( + font=terminalio.FONT, + text="Time Is:\n{}".format(time.monotonic()), + scale=2 +) + +# set label position on the display +updating_label.anchor_point = (0, 0) +updating_label.anchored_position = (20, 20) + +# add label to group that is showing on display +main_group.append(updating_label) + +# Main loop +while True: + + # update text property to change the text showing on the display + updating_label.text = "Time Is:\n{}".format(time.monotonic()) + + time.sleep(1) From a8b94316ad90778ed3b23f822432afc7d1e15c97 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 5 Dec 2021 16:15:43 -0600 Subject: [PATCH 2/2] code format --- CircuitPython_Display_Text/updating_text_example/code.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CircuitPython_Display_Text/updating_text_example/code.py b/CircuitPython_Display_Text/updating_text_example/code.py index eef238ebc..4db2fc57e 100644 --- a/CircuitPython_Display_Text/updating_text_example/code.py +++ b/CircuitPython_Display_Text/updating_text_example/code.py @@ -19,9 +19,7 @@ display.show(main_group) # create the label updating_label = label.Label( - font=terminalio.FONT, - text="Time Is:\n{}".format(time.monotonic()), - scale=2 + font=terminalio.FONT, text="Time Is:\n{}".format(time.monotonic()), scale=2 ) # set label position on the display