问题描述
我正在使用 Pygame 编写 Python 应用程序,该应用程序将输出到连接(通过适配器)到我的 RaspBerry Pi Zero W 的 HDMI 端口的 TFT 显示器的接口。
这是我的代码的简化版本:
import os
import sys
import pygame
import time
if __name__ == "__main__":
if sys.platform.startswith("linux"): # So I can develop and test on platforms other than Linux without this code running
drivers = ['directfb','fbcon','svgalib']
found = False
for driver in drivers:
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER',driver)
try:
pygame.display.init()
except pygame.error:
print('Driver: {0} Failed.'.format(driver))
continue
found = True
break
if not found:
raise Exception('No suitable video driver found!')
else:
pygame.display.init()
screen = pygame.display.set_mode((pygame.display.Info().current_w,pygame.display.Info().current_h),pygame.FULLSCREEN)
screen.fill((255,255,255))
logo = pygame.image.load("./image.png").convert()
screen.blit(logo,(0,0))
pygame.display.update()
time.sleep(5)
每次我使用 python3
运行代码时,都会引发各种异常之一。以下是我在运行代码之前采取的步骤(我没有做其他任何事情):
- 从 RaspBerry Pi 网站下载 RaspBerry Pi OS。我使用的是 Raspberry Pi OS Lite,发布日期为 2021 年 1 月 11 日,内核版本:5.4。
- 使用 BalenaEtcher 将图像刷写到微型 SD 卡。
- 插入 SD 卡并启动带有 TFT 显示屏(通过适配器)和无线 USB 键盘的 RaspBerry Pi。
- 使用
raspi-config
启用串行控制台。 - 通过 PuTTY 和控制台 USB 电缆(波特率 115200,这是默认值)连接并登录到 RaspBerry Pi。
-
sudo apt update && sudo apt upgrade -y
。然后,我安装 Git 并生成一个 SSH 密钥,以便我可以使用部署密钥从 GitHub 获取我的代码。 - 使用
python3
(或sudo python3
,也会引发异常)运行。
我收到我在代码中编写的异常:'No suitable video driver found!'
有人可以一步一步解释我需要在第 7 步之后做什么才能在 TFT 上显示 ./image.png 5 秒钟吗?另外,显然,我想要能够继续添加到我的程序中。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)