运行代码时,导入时会导致错误 代码取自GFXhat中RaspberryPi的示例部分 使用枕头的某个部位似乎有问题。不过,我不知道如何/是否有可能修复
def set_backlight(r, g, b):
backlight.set_all(r, g, b)
backlight.show()
menu_options = [
MenuOption('Set BL Red', set_backlight, (255, 0, 0)),
MenuOption('Set BL Green', set_backlight, (0, 255, 0)),
MenuOption('Set BL Blue', set_backlight, (0, 0, 255)),
MenuOption('Set BL Purple', set_backlight, (255, 0, 255)),
MenuOption('Set BL White', set_backlight, (255, 255, 255)),
MenuOption('Exit', sys.exit, (0,))
]
current_menu_option = 1
trigger_action = False
def handler(ch, event):
global current_menu_option, trigger_action
if event != 'press':
return
if ch == 1:
current_menu_option += 1
if ch == 0:
current_menu_option -= 1
if ch == 4:
trigger_action = True
current_menu_option %= len(menu_options)
for x in range(6):
touch.set_led(x, 0)
backlight.set_pixel(x, 255, 255, 255)
touch.on(x, handler)
backlight.show()
def cleanup():
backlight.set_all(0, 0, 0)
backlight.show()
lcd.clear()
lcd.show()
atexit.register(cleanup)
try:
while True:
image.paste(0, (0, 0, width, height))
offset_top = 0
if trigger_action:
menu_options[current_menu_option].trigger()
trigger_action = False
for index in range(len(menu_options)):
if index == current_menu_option:
break
offset_top += 12
for index in range(len(menu_options)):
x = 10
y = (index * 12) + (height / 2) - 4 - offset_top
option = menu_options[index]
if index == current_menu_option:
draw.rectangle(((x-2, y-1), (width, y+10)), 1)
draw.text((x, y), option.name, 0 if index == current_menu_option else 1, font)
w, h = font.getsize('>')
draw.text((0, (height - h) / 2), '>', 1, font)
for x in range(width):
for y in range(height):
pixel = image.getpixel((x, y))
lcd.set_pixel(x, y, pixel)
lcd.show()
time.sleep(1.0 / 30)
except KeyboardInterrupt:
cleanup()
root@DietPiT:/home/os/programs# python3 menu-options.py Traceback (most recent call last): File "menu-options.py", line 6, in from PIL import Image, ImageFont, ImageDraw File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 94, in from . import _imaging as core ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory
代码应该在GFX帽子上显示一个菜单
将.so所在的目录附加到LD\u LIBRARY\u PATH环境变量。你知道吗
通常这样的错误是因为库的打包不好。你知道吗
你有吗?那又怎样?你能在那个平台上安装带pip的枕头吗?你知道吗
相关问题 更多 >
编程相关推荐