RaspberryPi + PIL + Luma on SSD1351 Adafruit OLED text color and line spacing

时间:2022-04-24 00:25:02

I am new to Python and the RaspberryPi (coming from Arduino). At the moment I would like to assign the color to a text parsed from a website and I started by modifying one of the examples from the luma library (terminal). So far I can parse the text and print the OLED screen, but I cannot figure out where to pass the 'fill' value to color the text (ie blue o rgb o any color) I would also be able to control the line spacing, but I guess I will take one challenge at the time :)

我是Python和RaspberryPi(来自Arduino)的新手。目前我想将颜色分配给从网站解析的文本,我首先修改了luma库(终端)中的一个示例。到目前为止,我可以解析文本并打印OLED屏幕,但我无法弄清楚在哪里传递“填充”值来为文本着色(即蓝色或任何颜色)我也可以控制行间距,但我想我当时会接受一个挑战:)

Thanks for your help!

谢谢你的帮助!

import time
from demo_opts import get_device
from luma.core.virtual import terminal
from PIL import ImageFont 
import requests

r =requests.get('https://api.thingspeak.com/someapi)
def make_font(name, size):
font_path = os.path.abspath(os.path.join(
    os.path.dirname(__file__), 'fonts', name))
return ImageFont.truetype(font_path, size)

def main():
while True:
    #this one assigns the character and font size
    for fontname, size in [("Volter__28Goldfish_29.ttf", 24), ("miscfs_.ttf", 24)]:
        font = make_font(fontname, size) if fontname else None
        term = terminal(device, font)

        term.println(r.text)
        time.sleep(4)

if __name__ == "__main__":
try:
    device = get_device()
    main()
except KeyboardInterrupt:
    pass

GPIO.cleanup() 

1 个解决方案

#1


0  

I just realised it... The code is using Terminal from luma.core and the color needs to be passed after terminal is invoked, in this case it's:

我刚才意识到......代码是使用luma.core中的终端,并且在调用终端后需要传递颜色,在这种情况下它是:

term = terminal(device, font, color="red")

#1


0  

I just realised it... The code is using Terminal from luma.core and the color needs to be passed after terminal is invoked, in this case it's:

我刚才意识到......代码是使用luma.core中的终端,并且在调用终端后需要传递颜色,在这种情况下它是:

term = terminal(device, font, color="red")