Python Forum
pygame uploading image from opengameart
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame uploading image from opengameart
#1
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!
Reply
#2
(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?
Reply
#3
(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)
Reply
#4
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame Zero - no actor image toiling_away 2 1,795 Oct-14-2022, 12:16 AM
Last Post: toiling_away
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,307 Nov-10-2021, 03:38 PM
Last Post: metulburr
  open cv ->pygame: turn image into location Gamedeveloper 1 2,061 Jan-20-2020, 05:00 PM
Last Post: michael1789
  [PyGame] pygame image loading error BlueClaw 6 6,399 Dec-10-2019, 08:50 PM
Last Post: BlueClaw
  Finding the brightness of an image using pygame Zman350x 2 3,417 Feb-21-2019, 12:20 PM
Last Post: Zman350x
  [pyGame] Load Image, Problem Found ! JamieVanCadsand 2 8,753 Sep-29-2017, 06:26 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020