Text Windows¶
When you see CodeX, the LCD Display is front and center just crying out for some cool text and graphics to show! What are you waiting for? Just a little Python code and you’ll be on your way to awesome displays!
1. Text Messages¶
When you import the codex
module you get access to the display
object, which contains functions for displaying both
text and graphics on the screen. The display.print
function makes text output easy, and automatically handles
scrolling the display as more text is added.
from codex import *
display.print("Hello, World!")
2. Hello, Windowed World!¶
Scrolling text is nice, but if you want to build cool User Interfaces on the display you’ll want more control!
You can create multiple overlapping Windows that contain text and graphics, just like a smart-watch, phone, or computer OS.
Try the following code. It creates a “title” line with a blue background, then another small text box below with a counter.
from codex import *
from time import sleep
# Title: filled rectangle (x, y, width, height, color)
display.fill_rect(0, 0, 240, 35, BLUE)
display.draw_text('Reticulating Splines', scale=2, y=10, color=WHITE)
# Counter
display.fill_rect(95, 90, 50, 30, GREEN)
# Start counting up!
for i in range(1000):
display.draw_text(str(i), x=102, y=100, color=BLACK, background=GREEN, scale=2)
sleep(0.1)