Skip to content

Commit 7c28719

Browse files
committed
Error handling
1 parent f15c657 commit 7c28719

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

micropython/examples/inky_frame/display_png.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Create a PicoGraphics instance
77
graphics = PicoGraphics(DISPLAY)
8+
WIDTH, HEIGHT = graphics.get_bounds()
89

910
# Set the font
1011
graphics.set_font("bitmap8")
@@ -19,14 +20,18 @@
1920

2021
# Few lines of text.
2122
graphics.text("Display PNG Image...", 10, 40, 300, 3)
22-
graphics.text("Success!", 10, 70, 300, 3)
2323

2424
# Open our PNG File from flash. In this example we're using a green check mark.
2525
# You can use Thonny to transfer PNG Images to your Inky Frame.
26-
png.open_file("success.png")
26+
try:
27+
png.open_file("success.png")
2728

28-
# Decode our PNG file and set the X and Y
29-
png.decode(130, 70)
29+
# Decode our PNG file and set the X and Y
30+
png.decode(130, 70)
31+
32+
graphics.text("Success!", 10, 70, WIDTH, 3)
33+
except OSError:
34+
graphics.text("Unable to find PNG file! Copy 'success.png' to your Inky Frame using Thonny :)", 10, 70, WIDTH, 3)
3035

3136
# Start the screen update
3237
graphics.update()

0 commit comments

Comments
 (0)