4 from PIL
import Image
, ImageDraw
, ImageFont
8 format
='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
10 datefmt
='%Y-%m-%d %H:%M:%S')
12 logging
.info("""lcd.py - Hello, World! example on the 0.96" LCD.
18 # Create LCD class instance.
31 # Width and height to calculate text position.
35 # New canvas to draw on.
36 img
= Image
.new('RGB', (WIDTH
, HEIGHT
), color
=(0, 0, 0))
37 draw
= ImageDraw
.Draw(img
)
41 font
= ImageFont
.truetype("fonts/Asap/Asap-Bold.ttf", font_size
)
42 text_colour
= (255, 255, 255)
43 back_colour
= (0, 170, 170)
45 message
= "Hello, World!"
46 size_x
, size_y
= draw
.textsize(message
, font
)
48 # Calculate text position
49 x
= (WIDTH
- size_x
) / 2
50 y
= (HEIGHT
/ 2) - (size_y
/ 2)
52 # Draw background rectangle and write text.
53 draw
.rectangle((0, 0, 160, 80), back_colour
)
54 draw
.text((x
, y
), message
, font
=font
, fill
=text_colour
)
62 # Turn off backlight on control-c
63 except KeyboardInterrupt: