Is there any other way to load a resource like an image, sound, or font into Pygame? [closed]

Place the image file in the same directory as the Python file. Change the current working directory to the directory of the file.
The name and path of the file can be get by __file__. The current working directory can be get by os.getcwd() and can be changed by os.chdir(path):

import os

sourceFileDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(sourceFileDir)

Now you can use a relative path to load the file:

player = pygame.image.load("player.png")

Leave a Comment