tp2008
tp2008

Reputation: 21

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

Upvotes: 1

Views: 76

Answers (2)

Joystick
Joystick

Reputation: 304

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.

Upvotes: 3

Alec
Alec

Reputation: 9575

You never defined Sprite within an accessible scope for your class. This is likely the result of a neglected/faulty import.

Upvotes: 0

Related Questions