Python Forum

Full Version: pygame uploading image from opengameart
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi
hi I am learning pygame please.I am using windows computer.Please I want to upload images from opengameart.org.
I have downloaded them for my game.Please see the error that comes in my pygame.Please help me with this.
Many thanks
The error when I run the code in IDLE shell is as following:
Traceback (most recent call last):
File "C:\Users\ammah\OneDrive\Documents\project1\templae.py", line 84, in <module>
background = pygame.image.load(path.join(img_dir,"ship1.jpg")).convert()
pygame.error: Couldn't open C:\Users\ammah\OneDrive\Documents\project1\ship1.jpg\ship1.jpg

The code that I have written is the following:
import pygame
import random
from os import path

img_dir = path.join(path.dirname(__file__),"ship1.jpg")
#Load all game graphics
background = pygame.image.load(path.join(img_dir,"ship1.jpg")).convert()
background_rect = background.get_rect()
screen.blit(backgound, background_rect)


please help!
(Apr-15-2019, 07:44 PM)fatimabttt Wrote: [ -> ]pygame.error: Couldn't open C:\Users\ammah\OneDrive\Documents\project1\ship1.jpg\ship1.jpg
Do you have a folder named ship1.jpg? And does that folder have an image named ship1.jpg?
(Apr-15-2019, 08:20 PM)nilamo Wrote: [ -> ]
(Apr-15-2019, 07:44 PM)fatimabttt Wrote: [ -> ]pygame.error: Couldn't open C:\Users\ammah\OneDrive\Documents\project1\ship1.jpg\ship1.jpg
Do you have a folder named ship1.jpg? And does that folder have an image named ship1.jpg?

hi
Please see the following error:
Traceback (most recent call last):
File "C:\Users\ammah\OneDrive\Documents\project1\myCode.py.py", line 84, in <module>
background = pygame.image.load(path.join(img_dir,"ship1.jpg")).convert()
pygame.error: Couldn't open C:\Users\ammah\OneDrive\Documents\project1\ship1.jpg
>>>
project1 is name of folder
ship1.jpg is the image name

Please see my coding below:
img_dir = path.dirname(__file__)
background = pygame.image.load(path.join(img_dir,"ship1.jpg")).convert()
background_rect = background.get_rect()
screen.blit(background, background_rect)
(Apr-16-2019, 07:48 PM)fatimabttt Wrote: [ -> ]pygame.error: Couldn't open C:\Users\ammah\OneDrive\Documents\project1\ship1.jpg
The error says it can't open the file. It either doesn't exist, or might be locked (if it's open in another program).

So, in the folder "C:\Users\ammah\OneDrive\Documents\project1", you have at least these two files, correct? myCode.py.py and ship1.jpg