微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 PyGame 指向 Raspberry Pi OS Lite 上的帧缓冲区

如何解决将 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 运行代码时,都会引发各种异常之一。以下是我在运行代码之前采取的步骤(我没有做其他任何事情):

  1. 从 RaspBerry Pi 网站下载 RaspBerry Pi OS。我使用的是 Raspberry Pi OS Lite,发布日期为 2021 年 1 月 11 日,内核版本:5.4。
  2. 使用 BalenaEtcher 将图像刷写到微型 SD 卡。
  3. 插入 SD 卡并启动带有 TFT 显示屏(通过适配器)和无线 USB 键盘的 RaspBerry Pi。
  4. 使用 raspi-config 启用串行控制台。
  5. 通过 PuTTY 和控制台 USB 电缆(波特率 115200,这是认值)连接并登录到 RaspBerry Pi。
  6. sudo apt update && sudo apt upgrade -y。然后,我安装 Git 并生成一个 SSH 密钥,以便我可以使用部署密钥从 GitHub 获取我的代码
  7. 使用 python3(或 sudo python3,也会引发异常)运行。

我收到我在代码中编写的异常:'No suitable video driver found!'

有人可以一步一步解释我需要在第 7 步之后做什么才能在 TFT 上显示 ./image.png 5 秒钟吗?另外,显然,我想要能够继续添加到我的程序中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。