所以这是我的一款名为Zombie Dice的游戏。
我已经导入了图片,但是我收到了这个错误,我不明白为什么。请为我解释一些可能性。
"File "<pyshell#0>", line 1, in <module>
Game()
File "C:\Users\Brandon\Desktop\FinalProject3.py", line 17, in Game
Yellow = DieViewYellow(Gamewindow, Point(95,75),20)
File "C:\Users\Brandon\Desktop\DieViewYellow.py", line 83, in __init__
p1 = Point(x-25, y-25)
NameError: name 'Point' is not defined">
这是我的Die视图类,即使导入图形也会给我一个问题
#Die View Yellow
from graphics import *
class DieViewYellow:
def __init__(self, win, center, value):
"""Create a view of a die, e.g.:
d1 = GDie(myWin, Point(40,50), 20)
creates a die centered at (40,50) having sides
of length 20."""
# first define some standard values
self.win = win
#self.background = Color # color of die face
#self.foreground = Color2 # color of the pips
# create a square for the face
if value==0:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
if value == 1:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Brain=Text(Point(95,75),'B')
self.Brain.draw(self.win)
elif value == 2:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Brain=Text(Point(95,75),'B')
self.Brain.draw(self.win)
elif value == 3:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Shotgun=Text(Point(95,75),'S')
self.Shotgun.draw(self.win)
elif value == 4:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Foot=Text(Point(95,75),'F')
self.Foot.draw(self.win)
elif value == 5:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Foot=Text(Point(95,75),'F')
self.Foot.draw(self.win)
else:
x, y = center.getX(), center.getY()
p1 = Point(x-25, y-25)
p2 = Point(x+25, y+25)
rect = Rectangle(p1,p2)
rect.draw(win)
rect.setFill('yellow')
self.Shotgun=Text(Point(95,75),'S')
self.Shotgun.draw(self.win)
答案 0 :(得分:2)
你没有显示所有代码,但我相信你有这样的东西作为你的import语句:
import graphics
或
from module import graphics
您正在尝试使用Point
类:
p2 = Point(x+25, y+25) # This fails.
但是Python并不知道Point
模块中存在graphics
。无论何时使用Point
:
p2 = graphics.Point(x+25, y+25) # This works fine!
如果您想在没有Point
前缀的情况下使用graphics
,可以直接从graphics.
导入from graphics import Point
p2 = Point(x+25, y+25) # This works fine now!
。
{{1}}
修改强>
问题已被编辑,所以这个答案现在有点多余。我会留下它。