【发布时间】:2020-02-05 10:22:41
【问题描述】:
当我输入这个...
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
我明白了……
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
【问题讨论】:
-
你能确定
Sprite这个类是在这个上面定义的吗? -
它说
Sprite没有定义,你没有告诉我们你定义它的地方 -
Sprite来自哪里?它是否在其他文件中定义?然后你需要import它。它是在同一个文件中定义的吗?那么请向我们展示您的完整代码。 -
你的错误和你的代码不匹配:你有
class doorsprite(Sprite):或class DoorSprite(Sprite):吗? (但这只是一个旁注。)