I use a Raspberry Pi 4 B with a touchscreen. As OS I use the Raspberry Pi OS with desktop. I am currently working on a digital assistant. I wrote the code on my windows PC but want to run the assistant on my Raspberry pi. But when I start the program I receive the following error:
pygame.error: Couldn't open image.PNG
As it is a bigger project, I'll try to show you just the code that is relevant for the GUI:
import pygame
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode([800, 480])
pygame.display.set_caption('P.I.A.')
screen_icon = pygame.image.load('image.PNG')
pygame.display.set_icon(screen_icon)
The image.PNG is in the same directory as the programm itself. What really bothers me is that the code works on my windows PC perfectly and does not work at all on my raspberry pi. I can open the image.PNG with an image viewing program.
I tried switching the PNG to a JPG and I also changed the name of the PNG. Both did not work.
Any ideas how I can solve this problem?
Edit:
I now also tried to change the working directory and tried to use os.path.join()
. Both did not work. The only difference was that it specified which path the picture was when I used option 2.