简体   繁体   English

在 3.5" 屏幕上的树莓派零上运行 pygame 脚本时遇到问题

[英]Having trouble running pygame script on raspberry pi zero on 3.5" screen

Im trying to run my test game-script written in pygame on my raspberry pi zero w on a 3.5" LCD screen (which is working).我试图在 3.5 英寸 LCD 屏幕上运行我用 pygame 编写的测试游戏脚本(正在运行)。

But I keep getting this error.但我不断收到这个错误。 And I haven't after ALOT of hours found a fix for this, does anyone know how to fix this?而且我在很多小时后都没有找到解决这个问题的方法,有人知道如何解决这个问题吗? Im running the latest version of Raspberry Pi OS lite我正在运行最新版本的 Raspberry Pi OS lite

Script:

import pygame

pygame.init()
win = pygame.display.set_mode()

x = 50
y = 50
width = 40
height = 60
velocity = 10

run = True 
while run:
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False


    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        x -= velocity

    if keys[pygame.K_RIGHT]:
        x += velocity

    if keys[pygame.K_UP]:
        y -= velocity

    if keys[pygame.K_DOWN]:
        y += velocity



    win.fill((0, 0, 0))
    pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    pygame.display.update()


pygame.quit()```






Error Message:
pygame 2.1.2 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
Traceback (most recent call last):
 File "/srv/Game/main.py", line 4, in <module>
    win = pygame.display.set_mode()
pygame.error: No available video device





I think you need to include your params in win = pygame.display.set_mode() like this: win = pygame.display.set_mode(size=(x,y), width=width, etc...)我认为您需要将参数包含在 win = pygame.display.set_mode() 中,如下所示: win = pygame.display.set_mode(size=(x,y), width=width, etc...)

You will need to declare those variables before win = pygame.display.set_mode()您需要在 win = pygame.display.set_mode() 之前声明这些变量

Are you executing from terminal or IDE?您是从终端还是 IDE 执行? Do you have one or more displays?您有一台或多台显示器吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM