python - 将 PyGame 指向 Raspberry Pi OS Lite 上的帧缓冲区
问题描述
我正在使用 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 步之后我需要做什么才能让 ./image.png 在 TFT 上显示 5 秒钟吗?此外,显然,我希望能够继续添加到我的程序中。
解决方案
推荐阅读
- windows - 为什么我的 AutoHotKey 脚本在按下 Enter/NumpadEnter 时不发送复选框 - 仅在单击按钮时?
- node.js - 来自 mongodb-memory-server 的 MongoMemoryReplSet 与 jest 抛出打开句柄错误
- flutter - 为什么颤振`pub get`更改pubspec.lock?
- c# - 无法使用 Visual Studio 2019 连接 MySQL 数据库
- android - 使用 React-native-ble-plx 创建绑定
- ios - NSAttributedString 的 UILabel 对齐方式
- angular - 数据未显示,但项目已存储
- javascript - 如何让 cookie 接受不同页面的按钮和功能?
- npm - npm-cli 如何使缓存无效
- amazon-web-services - 如何在 AWS 中为 Graviton2 处理器使用 YAML 构建 ARM-64 Docker 映像