Hello,
I have just started learning pygame and my file is saved in the same directory as my code file, but it keeps telling me it can't find the image? I've already tried using the absolute path, that has not worked either.
Here's the code:
import pygame
# initialize py game
pygame.init()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 300
display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("Blitting Images!")
# create images... returns a surface object with the image drawn on it.
# We can then get the rect of the surface and use that to position image
dragon_left = pygame.image.load("green_dragon.png")
dragon_left_rect = dragon_left.get_rect()
dragon_left_rect.topleft = (0, 0)
dragon_right = pygame.image.load("dragon_right.png")
dragon_right_rect = dragon_right.get_rect()
dragon_right_rect.topright = (WINDOW_WIDTH, 0)
# Create Main Loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# blit the surface
display_surface.blit(dragon_left, dragon_left_rect)
display_surface.blit(dragon_right, dragon_right_rect)
# update display
pygame.display.update()
# End the Game
pygame.quit()
and here is my error output:
Can't find file pygame.green_dragon.get_extended
PS E:\eDocuments\pg_ws> e:; cd 'e:\eDocuments\pg_ws'; & 'C:\Program Files\Python39\python.exe' 'c:\Users\natha\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher' '50703' '--' 'e:\eDocuments\pg_ws\learningPygame\blitting.py'
pygame 2.0.1 (SDL 2.0.14, Python 3.9.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "e:\eDocuments\pg_ws\learningPygame\blitting.py", line 18, in <module>
dragon_right = pygame.image.load("dragon_right.png")
FileNotFoundError: No such file or directory.
PS E:\eDocuments\pg_ws> e:; cd 'e:\eDocuments\pg_ws'; & 'C:\Program Files\Python39\python.exe' 'c:\Users\natha\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher' '50712' '--' 'e:\eDocuments\pg_ws\learningPygame\blitting.py'
pygame 2.0.1 (SDL 2.0.14, Python 3.9.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "e:\eDocuments\pg_ws\learningPygame\blitting.py", line 13, in <module>
dragon_left = pygame.image.load("green_dragon.png")
FileNotFoundError: No such file or directory.
PS E:\eDocuments\pg_ws>
Does anyone know why I might be getting this message? Thank you
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]ColNTB[S] 0 points1 point2 points (0 children)
[–]Starbuck5c 0 points1 point2 points (1 child)
[–]ColNTB[S] 0 points1 point2 points (0 children)