Home > Mobile >  Why isn't my image being found in Pygame?
Why isn't my image being found in Pygame?

Time:06-19

I was working on a space shooter game when I can across this problem:

  File "C:\Users\willi\PycharmProjects\Pygame Testing\main.py", line 15, in <module>
    icon = pygame.image.load("Images", "boss.png")
FileNotFoundError: No file 'Images' found in working directory 'C:\Users\willi\PycharmProjects\Pygame Testing'.

I am working in PyCharm where i created a directory called "Images" and I put all my icons and enemies. I wanted to put the boss as the icon but it didn't work. Please help me :(

CodePudding user response:

There are two things to note here:

  1. You do not need to specify the first parameter to be "Images". Just the path to the file will do (make sure that the path is relative to your current directory.) You can read up more about the pygame.image.load function here
  2. PyGame sometimes tends to misbehave with normal variables. It is always a good idea to make them global in the main scope.

CodePudding user response:

pygame.image.load takes in a filename as the first argument

'Images' is not a filename. Use icon = pygame.image.load("Images/boss.png")

(Read the docs here)

  • Related