Does anyone know how to fix this error about uploading a image in Pycharm?

I had a problem with loading the image here. Does anyone know how to load the image in a right way?
I did put the file where it comes from, like where u see below that it comes from Documents from my computer. Here below under #IMAGES you can see how I uploaded the image.

# Aeroblasters
import pygame


pygame.init()
Screen = width, height = 288, 512

info = pygame.display.Info()
width = info.current_w
height = info.current_h

if width >= height:
    win = pygame.display.set_mode(Screen, pygame.NOFRAME)
else:
    win = pygame.display.set_mode(
        Screen, pygame.NOFRAME.pygame.SCALED.pygame.FULLSCREEN
    )
# Colors

WHITE = (255, 255, 255)
BLUE = (30, 144, 255)

# IMAGES

bg = pygame.image.load('Documenten/bg.avif.png')

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K.ESCAPE or event.key == pygame.K.q:
                running = False
    pygame.draw.rect(win, WHITE(0, 0, WIDTH, HEIGHT), 5, border_radius=4)
    pygame.display.update()
pygame.quit()

Is that the correct path to the image in your Repl?

2 Likes

yes, this is the name of the image that i have saved in documents

Hey, @amel8star !

Can you please provide a link to the repl?

Do you mean this? @KAlexK

bg = pygame.image.load('Documenten/bg.avif.png')

No, Alex means a link to your project on Replit. (EX: https://replit.com/@username/project)

I don’t have a repl yet. Its like an image that i want to upload in Python for a game that i am making.

What do you mean “upload”? If you’re doing local dev, then the file wouldn’t be uploaded.

Its like a image that i have downloaded from google and then download if after in my documents on the computer.

Where is your script on your computer? It’d need to be exactly one level above to open the file the way you’re trying to.

@Firepup650

import pygame

pygame.init()
Screen = width, height = 288, 512

info = pygame.display.Info()
width = info.current_w
height = info.current_h

if width >= height:
    win = pygame.display.set_mode(Screen, pygame.NOFRAME)
else:
    win = pygame.display.set_mode(
        Screen, pygame.NOFRAME.pygame.SCALED.pygame.FULLSCREEN
    )
# Colors

WHITE = (255, 255, 255)
BLUE = (30, 144, 255)

# IMAGES

bg = pygame.image.load("Documenten/bg.avif.png")

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K.ESCAPE or event.key == pygame.K.q:
                running = False
    pygame.draw.rect(win, WHITE(0, 0, WIDTH, HEIGHT), 5, border_radius=4)
    pygame.display.update()
pygame.quit()

Where on your computer is the script?

Is that supposed to be Documents?

Yes, Documenten is like in my language Dutch.

Could you try changing this:

bg = pygame.image.load("Documenten/bg.avif.png")

to:

bg = pygame.image.load("C:/Users/USERNAME/Documenten/bg.avif.png")

replacing “USERNAME” with your username on your computer, and then try it?

I forget to mention something. Its like on my computer and then you click on documents and then you see above that is from me like the name amel and then besides it the name persoonlijk and then the documents so the image are in those…
Because of that i have added those in it, dont know if that was the right way to put it this way, but i sadly again did came across the error that it didnt couldt find the file.

import pygame


pygame.init()
Screen = width, height = 288, 512

info = pygame.display.Info()
width = info.current_w
height = info.current_h

if width >= height:
    win = pygame.display.set_mode(Screen, pygame.NOFRAME)
else:
    win = pygame.display.set_mode(
        Screen, pygame.NOFRAME.pygame.SCALED.pygame.FULLSCREEN
    )
# Colors

WHITE = (255, 255, 255)
BLUE = (30, 144, 255)

# IMAGES

bg = pygame.image.load("C:/User/amel/Persoonlijk/Documenten/bg.avif.png")

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K.ESCAPE or event.key == pygame.K.q:
                running = False
    pygame.draw.rect(win, WHITE(0, 0, WIDTH, HEIGHT), 5, border_radius=4)
    pygame.display.update()
pygame.quit()

Could you perhaps show a picture of the path to the File in File Explorer?

1 Like

Oh. It’s a file on OneDrive. That’s part of the problem. Try moving the file to the same folder as your script.

Also, that’s not a PNG image at all. it’s just an avif.

1 Like

I have changed it now, its now a JPG image because I the other image didnt suit it anymore I saw. And I also moved the file now to the file where the script is.
but it still gave me the error of not finding the file…

and here is the script:

# Aeroblasters
import pygame


pygame.init()
Screen = width, height = 288, 512

info = pygame.display.Info()
width = info.current_w
height = info.current_h

if width >= height:
    win = pygame.display.set_mode(Screen, pygame.NOFRAME)
else:
    win = pygame.display.set_mode(
        Screen, pygame.NOFRAME.pygame.SCALED.pygame.FULLSCREEN
    )
# Colors

WHITE = (255, 255, 255)
BLUE = (30, 144, 255)

# IMAGES

bg = pygame.image.load("C:amel/Persoonlijk/Documenten/Github/wp1-2023-pygame-1a1-retrodevs.bg.new air.jpg")

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K.ESCAPE or event.key == pygame.K.q:
                running = False
    pygame.draw.rect(win, WHITE(0, 0, WIDTH, HEIGHT), 5, border_radius=4)
    pygame.display.update()
pygame.quit()