I'm trying to make the base for a map that I'm going to be using for a game, but I can't load the image onto the screen. I've tried sending in an absolute filepath to the image with likesame letter case, I've tried changing the name of the image, I've tried loading different images that worked in other programs I made, and I've tried putting the image in the same directory as the script itself. Nothing has worked yet. I looked at a few threads of people who were having the same problem, such as Why are my pygame images not loading? and I can't find the answer to my problem. The image will not load. Here's the code:
import sys, pygame
from pygame.locals import *
pygame.init()
size = (600, 400)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Practice Map")
walls = pygame.image.load("C:\Users\dylan\Desktop\Practice Game\brick.jpg")
x = 0
y = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == KEYDOWN and event.key == K_ESCAPE:
sys.exit()
if event.type == KEYDOWN and event.key == K_UP:
y -= 20
if event.type == KEYDOWN and event.key == K_DOWN:
y += 20
if event.type == KEYDOWN and event.key == K_LEFT:
x -= 20
if event.type == KEYDOWN and event.key == K_RIGHT:
x += 20
screen.fill((0,0,0))
screen.blit(walls,(x, 330))
# more bricks to go here later
pygame.display.flip()
#end
and the error:
Traceback (most recent call last):
File "C:\Users\dylan\Desktop\Practice Game\move.py", line 8, in <module>
walls = pygame.image.load("C:\Users\dylan\Desktop\Practice Game\brick.jpg")
error: Couldn't open C:\Users\dylan\Desktop\Practice Gamerick.jpg
I'm using Python 2.6 with PyGame 1.9 for Python version 2.6 with IDLE as my editor.