Why is pygame coming up with the error cant load image

Why is pygame coming up with the error cant load image

Postby merlinthecat » Wed Nov 06, 2013 10:58 pm

Ok so im new to python more so to pygame. I have saved fifa.jpg in the python folder but it wont load.

Code: Select all
import pygame
from pygame import *
pygame.init()
window=pygame.display.set_mode((800,600) ,0,32)
pygame.display.set_caption("Fifa 14")
screen=pygame.display.get_surface()
text1="     Welcome To Fifa 14"
text2=" To Continue ,Sign Into EA"
myfont= pygame.font.SysFont("Britannic Bold", 55)
label1=myfont.render(text1, 1, (250, 0,0))
myfont= pygame.font.SysFont("Britannic Bold", 30)
label2=myfont.render(text2, 1, (250,0,0))
background=pygame.image.load('fifa.jpg')
window.blit(background,(0,0))
window.blit(label1, (0,20))
window.blit(label2, (500,550))
pygame.display.update()


The game window comes up but it is just black because the image isn't loading it just comes up with the error:
Code: Select all
Traceback (most recent call last):
  File "C:\Users\jason\pygame fifa14.py", line 13, in <module>
    background=pygame.image.load('fifa.jpg')
pygame.error: Couldn't open fifa.jpg
:evil: :evil: :evil: :evil: :evil:
Last edited by stranac on Wed Nov 06, 2013 11:01 pm, edited 1 time in total.
Reason: Added code tags. Locked.
merlinthecat
 
Posts: 4
Joined: Wed Nov 06, 2013 10:52 pm

Re: Why is pygame coming up with the error cant load image

Postby micseydel » Wed Nov 06, 2013 11:32 pm

What about if you specify the full path of the image file?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1214
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Why is pygame coming up with the error cant load image

Postby metulburr » Wed Nov 06, 2013 11:44 pm

1) ensure that the image is in the same location as the python file, as you have not specified a path
2) If that is accurate, try a different image and see if that does the same or not
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1381
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Why is pygame coming up with the error cant load image

Postby Kebap » Thu Nov 07, 2013 10:39 am

Welcome to python and welcome to the forums! :mrgreen: Here is another short suggestion for alike problems:
Code: Select all
import os
print os.path.abspath(os.curdir)

This will show you the current working directory. Check whether the picture is located in there or not.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 380
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests