import pygame
from pygame.locals import*
import sys
pygame.init()
screen=pygame.display.set_mode(480,360))
pygame.display.set_caption("Move the main character"")
player=pygame.image.load("annpannmann.png").convert_alpha()
while(1):
pygame.display.update()
screen.blit(player,playe.get_rect())
for event in pygame.event.get():
if event.type==quit:
pygame.quit()
sys.exit(0)
I'd like to load annpannmann.png, no matter how I change it,
error: Couldn't open annpannmann.png
The error statement appears.The extension should also be correct.What should I do?
python pygame
Most of the time, the file is missing in the current folder when the program is running.
Check it out.
How pygame.image.load() draws images in pygame
Trying to view images in pygame results in an error
This is a Python 2.x-based article that works normally. Draw an image
What to do if there are files in subfolders such as images
Python-error: couldn't open.png file
importos
current_path=os.path.dirname(__file__)#Where your.py file is located
resource_path=os.path.join(current_path, 'resources')#The resource folder path
image_path=os.path.join(resource_path, 'images')#The image folder path
player_image=pygame.image.load(os.path.join(image_path, 'dude.png')))
© 2024 OneMinuteCode. All rights reserved.