user1452509
user1452509

Reputation: 97

pygame image refuses to load

Code:

import pygame, sys

def load ():
    image = pygame.image.load ('ShrinSprite.jpg')
    return image, image.get_rect ()


class Sprite (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__ (self)
        self.image, self.rect = load ()

sprite = Sprite ()
allsprites = pygame.sprite.RenderClear ((sprite))

Surface = pygame.display.set_mode ((400, 400), 0, 32)

 while True:
    Surface.fill ((255, 255, 255))
    allsprites.draw (0, 0)

    for event in pygame.event.get ():
        if event.type == QUIT:
            pygame.quit ()
            sys.exit (0)

         if event.type == KEYDOWN:
            allsprites.draw (0, -5)
            allsprites.clear ()

    pygame.display.update ()

The error states that the image cannot be loaded:

pygame.error: Could not load 'ShrinSprite.jpg'

Although the image is in the same directory as the program, this error still keeps appearing

Upvotes: 2

Views: 187

Answers (1)

ThisIsAQuestion
ThisIsAQuestion

Reputation: 1977

This usually happens after you try to enter a command into the shell after running a program. To make it load, simply re-save the program.

Please let me know if this works.

Upvotes: 4

Related Questions