|
| 1 | +# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +""" |
| 5 | +Make green and purple rectangles and then update the color |
| 6 | +and text values of the labels using the get_cell() function. |
| 7 | +""" |
| 8 | +import board |
| 9 | +import displayio |
| 10 | +import terminalio |
| 11 | +from adafruit_display_text import label |
| 12 | +from adafruit_displayio_layout.layouts.grid_layout import GridLayout |
| 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 |
| 17 | +display = board.DISPLAY |
| 18 | + |
| 19 | +# Make the display context |
| 20 | +main_group = displayio.Group() |
| 21 | +display.show(main_group) |
| 22 | + |
| 23 | +layout = GridLayout( |
| 24 | + x=10, |
| 25 | + y=10, |
| 26 | + width=200, |
| 27 | + height=100, |
| 28 | + grid_size=(2, 2), |
| 29 | + cell_padding=8, |
| 30 | +) |
| 31 | +_labels = [] |
| 32 | + |
| 33 | +_labels.append( |
| 34 | + label.Label( |
| 35 | + terminalio.FONT, scale=2, x=0, y=0, text="Hello", background_color=0x770077 |
| 36 | + ) |
| 37 | +) |
| 38 | +layout.add_content(_labels[0], grid_position=(0, 0), cell_size=(1, 1)) |
| 39 | +_labels.append( |
| 40 | + label.Label( |
| 41 | + terminalio.FONT, scale=2, x=0, y=0, text="World", background_color=0x007700 |
| 42 | + ) |
| 43 | +) |
| 44 | +layout.add_content(_labels[1], grid_position=(1, 0), cell_size=(1, 1)) |
| 45 | +_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Hello")) |
| 46 | +layout.add_content(_labels[2], grid_position=(0, 1), cell_size=(1, 1)) |
| 47 | +_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Grid")) |
| 48 | +layout.add_content(_labels[3], grid_position=(1, 1), cell_size=(1, 1)) |
| 49 | + |
| 50 | +main_group.append(layout) |
| 51 | + |
| 52 | +layout.get_cell((0, 0)).text = "Happy" |
| 53 | +layout.get_cell((1, 0)).text = "Circuit" |
| 54 | + |
| 55 | +layout.get_cell((0, 1)).text = "Python" |
| 56 | +layout.get_cell((1, 1)).text = "Day" |
| 57 | + |
| 58 | +layout.get_cell((0, 1)).background_color = 0x007700 |
| 59 | +layout.get_cell((1, 1)).background_color = 0x770077 |
| 60 | + |
| 61 | +while True: |
| 62 | + pass |
0 commit comments