1

I am trying to put an image but it keeps saying pygame.error: Couldn't open racecar.png I don't know what I am doing wrong. Is it the pygame version that I use, the version of python, problem with the ide I use, or something else? The version of pygame I use is pygame 2.0.0 dev6 The version of python I use is python 3.8.6 The ide that I use is VS code here is my code:

import pygame


 pygame.init()


 display_width = 800
 display_height = 600

 gameDisplay = pygame.display.set_mode((display_width,display_height))
 pygame.display.set_caption('A bit Racey')

 black = (0,0,0)
 white = (255,255,255)

 clock = pygame.time.Clock()
 crashed = False
 carImg = pygame.image.load('racecar.png')

 def car(x,y):
     gameDisplay.blit(carImg, (x,y))

 x =  (display_width * 0.45)
 y = (display_height * 0.8)

 while not crashed:
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             crashed = True

     gameDisplay.fill(white)
     car(x,y)

    
     pygame.display.update()
     clock.tick(60)

 pygame.quit()
 quit()

1 Answers1

2

It could just be that the path to "racecar.png" is not the local directory but some other directory.

It is probably trying to open the file in the same folder as where your *.exe is located, try a full path name or a relative path (relative probably to your *.exe file path), something like: ..\..\images\racecar.png

DKomen
  • 31
  • 3
  • That doesn’t work:( I have it stored in documents then screenshots so I did pygame.image.load(“Documents\screenshots\racecar.png”) –  Oct 27 '20 at 00:17
  • Try typing the full path.. all the way from the root drive: like C:\..\..\..Documents\screenshots\racecar.png If that works then it is a relative path issues – DKomen Oct 27 '20 at 23:42