python - pygame.error: Couldn't open image.bmp -
whenever run code message pygame.error: couldn't open ship.bmp appears. keeping file ship.bmp in same place code. appreciate help.
import sys import pygame pygame.init() screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width,screen_height)) bg_color = (0, 13, 114) pygame.display.set_caption('space invaders') shipimg = pygame.image.load("ship.bmp") def ship(x,y): screen.blit(shipimg, (x,y)) x = (screen_width * 0.45) y = (screen_height * 0.8) crashed = false while not crashed: #keyboard events event in pygame.event.get(): if event.type == pygame.quit: crashed = true screen.fill(bg_color) ship(x,y) pygame.display.flip() pygame.quit() quit()
i tried code , worked fine. see image in root directory. same folder save script/py file. other reason there hidden characters in file name. happened me several times. try rename function, delete entire name including file extension , rename file same ext, brand new.
Comments
Post a Comment