Search code examples
pythonnameerror

can't stop nameerror in python


When I type this...

class doorsprite(Sprite):
     def __init__(self, game, photo_image, x, y, width, height):
            Sprite.__init__(self, game)
            self.photo_image = photo_image
            self.image = game.canvas.create_image(x, y, \
                    image=self.photo_image, anchor='nw')
            self.coordinates = Coords(x, y, x + (width / 2), y + height)
            self.endgame = True

I get...

Traceback (most recent call last):
  File "C:\Users\telta\Desktop\stickman game.py", line 94, in <module>
    class DoorSprite(Sprite):
NameError: name 'Sprite' is not defined

Solution

  • You are probably reading this from book A playful introduction on programming You are missing out on the Sprite class which is given on later in the book. You can go back and search for the sprite function. Have fun building stickman game. Thank you.