I was trying to load a png file to python by pygame and it doesn't work this is my code:
import pygame
from pygame.locals import *
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Game")
clock = pygame.time.Clock()
carImage = pygame.image.load('you.png')
def car(x,y):
gameDisplay.blit(carImage,(x,y))
x = (display_width * 0.45)
y = (display_height * 0.8)
crashed = False
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(24)
pygame.quit()
quit()
and it says:
Traceback (most recent call last):
File "C:/Users/Dawn/PycharmProjects/snakegame/snake.py", line 13, in carImage = pygame.image.load('you.png')
pygame.error: Couldn't open you.png
Please help me I don't know why this keep showing.
I'm using window 10 now and I did the C: \.\...\you.png
method
but it still doesn't work.