pydisplay in Jupyter¶
ReadTheDocs shows this notebook as static text only — no kernel, no live widget. To run it interactively, follow Run the notebook interactively (JupyterLab or VS Code).
Walkthrough: board config → display tricks → graphics → one-shot examples → clear → async touch demos.
Requires: pip install pillow ipywidgets ipyevents
VS Code / Cursor: jupyter.widgetScriptSources — see ipywidgets in VS Code.
Click the ipywidgets Image below each cell for touch (not the cell chrome). Kernel → Restart stops background async examples.
Board config¶
import lib.path adds lib/, examples/, and add_ons/ to sys.path. Importing board_config creates display_drv (JNDisplay) and broker for input events.
import lib.path
import board_config
from board_config import display_drv, broker
print(display_drv.__class__.__name__, f"{display_drv.width}×{display_drv.height}", f"TIMER_ASYNC={board_config.TIMER_ASYNC}")
Display: rotation and blit¶
Try each rotation, then blit a small RGB565 buffer onto the canvas.
from board_config import display_drv
colors = (0xF800, 0x07E0, 0x001F, 0xFFE0) # red, green, blue, yellow
for rot, color in zip((0, 90, 180, 270), colors):
display_drv.rotation = rot
display_drv.fill(color)
display_drv.show()
display_drv.rotation = 0
display_drv.fill(0)
w, h = 48, 48
buf = bytearray(w * h * 2)
for y in range(h):
for x in range(w):
i = (y * w + x) * 2
buf[i] = (x * 5) & 0xFF
buf[i + 1] = (y * 5) & 0xFF
display_drv.blit_rect(buf, 20, 20, w, h)
display_drv.show()
Graphics: draw and text¶
Use graphics and a palette — same API as on microcontrollers and desktop.
import graphics
from palettes import get_palette
from board_config import display_drv
pal = get_palette("material_design")
graphics.fill(display_drv, pal.BLUE_S900)
graphics.round_rect(display_drv, 24, 80, display_drv.width - 48, 72, 12, pal.AMBER_S500, True)
graphics.text(display_drv, "graphics + palettes", 48, 108, pal.BLACK)
graphics.circle(display_drv, display_drv.width // 2, 280, 56, pal.GREEN_S400, True)
graphics.line(display_drv, 0, 0, display_drv.width - 1, display_drv.height - 1, pal.WHITE)
display_drv.show()
One-shot examples¶
These modules draw once and return (no event loop). Uncomment one import, run the cell, then clear the display before trying another — overlapping is fine if you want to compare.
# import logo # concentric logo (graphics)
# import graphics_simpletest # shapes and built-in font
# import framebuf_simpletest # draw to a framebuffer, then blit
# import font_list # list .bin fonts from examples/assets/
import chango.chango # TrueType fonts via tft_write (add_ons)
Clear the display¶
Run this between one-shot examples (or anytime) to reset the canvas.
from board_config import display_drv
display_drv.fill(0)
display_drv.show()
Async touch examples¶
These use multimer.run() — the cell returns immediately while the demo runs in the background. Uncomment one import per try; restart the kernel before switching async examples or to stop.
See Jupyter platform notes for why asyncio is required here.
# import eventsys_simpletest # print pointer events when you click the widget
# import paint # finger painting with color palette
# import calculator # touch calculator UI
# import eventsys_touch_test # touch rotation calibration (four corners × four rotations)
# import apollo # Apollo DSKY demo (best at 320×480)
import pydisplay_demo_async # widget gallery with asyncio timers