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).
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
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...)
You will need to declare those variables before win = pygame.display.set_mode()
Are you executing from terminal or IDE? Do you have one or more displays?