Python Forum
pygame image load error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pygame image load error (/thread-38433.html)



pygame image load error - Yegor123 - Oct-12-2022

Hi Im new to pygame and Coding in general And I just started a tutorial and Whenever I try and load my png images and I run the code i shows up as an error here is my code
import pygame

from pygame.locals import *

pygame.init()

screen_width = 800
screen_height = 600

screen = pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption('Platformer')

#load images

bg_img = pygame.image.load("img/sky.png")


run = True
while run:

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

    screen.blit(bg_img, (0,0))

    pygame.display.update()

pygame.quit()
Whenever I try and do This It come up as an Error such as this

Error:
FileNotFoundError: No file 'img/sky.png' found in working directory 'C:\Users\yeg20\OneDrive\Desktop\workspace'.
Could anyone tell me why this is happening and how to fix it?


RE: pygame image load error - deanhystad - Oct-12-2022

Your program is trying to open a file named 'C:\Users\yeg20\OneDrive\Desktop\workspace\img/sky.png'. The file does not exist.