简体   繁体   English

无法停止 python 中的名称错误

[英]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

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.您可能正在阅读本书A playful Introduction on Programming您错过了本书后面给出的 Sprite class。 You can go back and search for the sprite function.您可以返回 go 并搜索精灵 function。 Have fun building stickman game.玩得开心建造火柴人游戏。 Thank you.谢谢你。

You never defined Sprite within an accessible scope for your class.您从未在 class 的可访问 scope 中定义Sprite This is likely the result of a neglected/faulty import.这很可能是导入被忽略/错误的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM