Created
March 25, 2019 20:21
-
-
Save alopresto/231287e62aac84f21f7b756351fecde0 to your computer and use it in GitHub Desktop.
Python script to display two lines of different-colored text on Inky pHAT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from inky import InkyPHAT | |
inky_display = InkyPHAT("red") | |
inky_display.set_border(inky_display.WHITE) | |
from PIL import Image, ImageFont, ImageDraw | |
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) | |
draw = ImageDraw.Draw(img) | |
from font_fredoka_one import FredokaOne | |
font = ImageFont.truetype(FredokaOne, 22) | |
line1 = "MiNiFi 0.6.0 on" | |
line2 = "Raspberry Pi 3 B+" | |
line_padding = 6 | |
w1, h1 = font.getsize(line1) | |
x = (inky_display.WIDTH / 2) - (w1 / 2) | |
y = (inky_display.HEIGHT / 2) - h1 - (line_padding / 2) | |
draw.text((x, y), line1, inky_display.RED, font) | |
w2, h2 = font.getsize(line2) | |
x = (inky_display.WIDTH / 2) - (w2 / 2) | |
y = (inky_display.HEIGHT / 2) + (line_padding / 2) | |
draw.text((x, y), line2, inky_display.BLACK, font) | |
inky_display.set_image(img) | |
inky_display.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment