Why are my pygame images not loading?
Question: I found a tutorial online (on Youtube) and it showed me the basics of creating
a game with pygame. i found images of the kind he said and what he had. he
didn't say where to save them to, i think that may be my problem. here, this
is an example of what i have in my program and what shows up on the error

    
    
    bif="bg.jpg"
    mif="images.png"
    
    import pygame, sys
    from pygame.locals import *
    
    pygame.init()
    screen=pygame.display.set_mode((420,315),0,32)
    
    backround=pygame.image.load(bif).convert()
    mouse_c=pygame.image.load(mif).convert_alpha()
    
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
    
        screen.blit(backround, (0,0))
    
        x,y = pygame.mouse.get_pos()
        x -= mouse_c.get_width()/2
        y -+ mouse_c.get_height()/2
    
        screen.blit(mouse_c, (x,y))
    
        pygame.display.update()
    

the error reads:

    
    
    Traceback (most recent call last):  
    File "C:/Python26/pygame.games/pygame
    1", line 10, in <module>
        backround=pygame.image.load(bif).convert()
    error: Couldn't open bg.jpg
    

please respond as soon as possible.


Answer: Based on that code, your image files need to be saved in the same directory as
your game's .py file. Try moving them there.

As a sanity check (to make sure the images will load and it is in fact an
issue with supplying the correct path) you could temporarily specify an
absolute path to the image in your code, so instead of

    
    
    bif = "bg.jpg"
    

You would have

    
    
    bif = "C:/My_game/images/bg.jpg"
    

But obviously change the second bit to point to where your image is actually
stored. Once you're sure that the image can be loaded using an absolute path,
you should use a relative path, and if you're likely to have many assets you
should keep them separate from the code, for example by putting them in an
`assets` folder in the same folder as your game code, or similar.

    
    
    bif = "assets/bg.jpg"
    

