zkhan122
zkhan122

Reputation: 73

Getting "NotADirectoryError" Python

I am trying to test an image as a background using pygame. I have been trying to fix this issue for a few days, and now have resolved to StackOverflow

The line I have written to load the image:

back_ground = pygame.image.load(os.chdir(r"C:\Users\zayaa\Desktop\GameSprites\L9.png"))

I have used a directory but I get "NotADirectoryError [WinError 267]"

I have already attempted the following:

back_ground = pygame.image.load(os.chdir(r"C:\\Users\\zayaa\\Desktop\\GameSprites\\L9.png"))
back_ground = pygame.image.load("C:/Users/zayaa/Desktop/GameSprites/L9.png")
back_ground = pygame.image.load("C://Users//zayaa//Desktop//GameSprites//L9.png")

Can someone please tell me how to fix this?

Thank you,

OP

Upvotes: 1

Views: 522

Answers (1)

Rabbid76
Rabbid76

Reputation: 210918

os.chdir changes the current working directory to path, but does not return anything.

back_ground = pygame.image.load(os.chdir(r"C:\Users\zayaa\Desktop\GameSprites\L9.png"))

back_ground = pygame.image.load(r"C:\Users\zayaa\Desktop\GameSprites\L9.png")

However, you can change the working directory and then load the file:

os.chdir(r"C:\Users\zayaa\Desktop\GameSprites")
back_ground = pygame.image.load("L9.png")

Upvotes: 1

Related Questions