0
background = pygame.image.load('example.jpg')
nubjuk = pygame.image.load('nubjuk.png')
nubjuk = pygame.transform.scale(nubjuk, (200,90))

This is the code part of the problem and the error message is:

Exception has occurred: error Couldn't open example.jpg

I think I've tried every solution uploaded in other StackOverflow questions.(os.path ~, absolute path, just anything) However, they don't work. More weird thing is that it properly worked yesterday, but even though I didn't touch anything it doesn't work today.

What's the problem?

Jinwon Lee
  • 13
  • 3
  • Does this answer your question? [Error - pygame.error: Couldn't open backround.png. Fix?](https://stackoverflow.com/questions/57836528/error-pygame-error-couldnt-open-backround-png-fix) – Rabbid76 Dec 31 '19 at 09:11

1 Answers1

0

Your code expects the files 'example.jpg' and 'nubjuk.png' to be in the current working directory.

Obviously this is not the case. Either you changed the working directory prior to calling your script or your script changes the working directory. or you moved the png files to a different directory (or deleted them)

If the .png files are in the same directory than your python script you can do something like that at the beginning of your file.

import os

MYDIR = os.path.realpath(os.path.dirname(__file__))

and then replace your two image.load lines with

background = pygame.image.load(os.path.join(MYDIR, 'example.jpg'))
nubjuk = pygame.image.load(os.path.join(MYDIR, 'nubjuk.png'))
gelonida
  • 5,327
  • 2
  • 23
  • 41