Skip to content

Instantly share code, notes, and snippets.

@FoamyGuy
Created September 5, 2021 21:43
Show Gist options
  • Save FoamyGuy/15452847dfd70663edb6d7d1d43377f2 to your computer and use it in GitHub Desktop.
Save FoamyGuy/15452847dfd70663edb6d7d1d43377f2 to your computer and use it in GitHub Desktop.
# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Make green and purple rectangles and a
"Hello World" label. Displayed with Blinka_Displayio_PyGameDisplay
"""
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_displayio_layout.widgets.widget import Widget
from blinka_displayio_pygamedisplay import PyGameDisplay
# Make the display context. Change size if you want
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
display = PyGameDisplay(width=400, height=300)
main_group = displayio.Group()
display.show(main_group)
layout = GridLayout(
x=10,
y=10,
width=320,
height=100,
grid_size=(2, 2),
cell_padding=8,
divider_lines=True
)
_labels = []
_widgets = []
_widgets.append(Widget())
layout.add_content(_widgets[0], grid_position=(0, 0), cell_size=(1, 1))
_labels.append(
label.Label(
terminalio.FONT, scale=2,
anchor_point=(0.5, 0), anchored_position=(_widgets[0].width//2, 0),
text="Hello", background_color=0x770077
)
)
_widgets[0].append(_labels[0])
_widgets.append(Widget())
layout.add_content(_widgets[1], grid_position=(1, 0), cell_size=(1, 1))
_labels.append(
label.Label(
terminalio.FONT, scale=2,
anchor_point=(0.5, 0), anchored_position=(_widgets[1].width//2, 0),
text="World", background_color=0x007700
)
)
_widgets[1].append(_labels[1])
_widgets.append(Widget())
layout.add_content(_widgets[2], grid_position=(0, 1), cell_size=(1, 1))
_labels.append(label.Label(
terminalio.FONT, scale=2,
anchor_point=(0.5, 0), anchored_position=(_widgets[2].width//2, 0),
text="Hello")
)
_widgets[2].append(_labels[2])
_widgets.append(Widget())
layout.add_content(_widgets[3], grid_position=(1, 1), cell_size=(1, 1))
_labels.append(label.Label(
terminalio.FONT,
anchor_point=(0.5, 0), anchored_position=(_widgets[3].width//2, 0),
scale=2, text="Grid")
)
_widgets[3].append(_labels[3])
main_group.append(layout)
while display.running:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment