python中为什么undraw会出现keyerror
classBall():def__init__(self,pic,catchincrease,cost,web):self.cain=catchincreaseself....
class Ball():
def __init__(self,pic,catchincrease,cost,web):
self.cain = catchincrease
self.cost = cost
self.web = web
self.image = Image(Point(500,1),pic)
def shoot(self): ## can't shoot 2 balls sequently
def callback(event):
def getK():
dx = event.x - 500
dy = 599 - event.y
self.k = float(dy) / dx
return self.k
def bump():
if ball.k > 0:
for i in range(len(SpeciesList)):
for j in range(len(SpeciesList[i].a)):
if SpeciesList[i].a[j].image.getAnchor().getX()+SpeciesList[i].a[j].image.getWidth()/2.0 > x.getAnchor().getX()+15 > SpeciesList[i].a[j].image.getAnchor().getX() - SpeciesList[i].a[j].image.getWidth()/2.0 and SpeciesList[i].a[j].image.getAnchor().getY() + SpeciesList[i].a[j].image.getHeight()/2.0 > x.getAnchor().getY()+15 > SpeciesList[i].a[j].image.getAnchor().getY() - SpeciesList[i].a[j].image.getHeight()/2.0:
return True
else:
## print x.getAnchor().getX()
## print x.getAnchor().getY()
## print PokemonList[i].image.getAnchor().getX()
## print PokemonList[i].image.getAnchor().getY()
pass
return False
if ball.k < 0:
for i in range(len(PokemonList)):
try:
if 。。。:
return True
else:
pass
except:IndexError
return False
x = self.image.clone()
x.draw(win)
s=abs(getK())/((getK()**2+1)**0.5)
h=getK()/((getK()**2+1)**0.5)/abs(getK())
while 0 < x.getAnchor().getY() < 600 and 0 < x.getAnchor().getX() < 1000:
if not bump():
x.move(10 * h , 10 * s)
sleep(0.01)
if bump():
## bump()
global web
web = Image(x.getAnchor(),'web.gif')
web.draw(win)
x.undraw()
cover()
print coverList
for i in range(len(coverList)):
if coverList[i].caught():
coverList[i].image.undraw()
x.undraw()
win.bind("<Button-1>",callback)
win.pack()
win.mainloop()
有哪些原因会出现keyerror 展开
def __init__(self,pic,catchincrease,cost,web):
self.cain = catchincrease
self.cost = cost
self.web = web
self.image = Image(Point(500,1),pic)
def shoot(self): ## can't shoot 2 balls sequently
def callback(event):
def getK():
dx = event.x - 500
dy = 599 - event.y
self.k = float(dy) / dx
return self.k
def bump():
if ball.k > 0:
for i in range(len(SpeciesList)):
for j in range(len(SpeciesList[i].a)):
if SpeciesList[i].a[j].image.getAnchor().getX()+SpeciesList[i].a[j].image.getWidth()/2.0 > x.getAnchor().getX()+15 > SpeciesList[i].a[j].image.getAnchor().getX() - SpeciesList[i].a[j].image.getWidth()/2.0 and SpeciesList[i].a[j].image.getAnchor().getY() + SpeciesList[i].a[j].image.getHeight()/2.0 > x.getAnchor().getY()+15 > SpeciesList[i].a[j].image.getAnchor().getY() - SpeciesList[i].a[j].image.getHeight()/2.0:
return True
else:
## print x.getAnchor().getX()
## print x.getAnchor().getY()
## print PokemonList[i].image.getAnchor().getX()
## print PokemonList[i].image.getAnchor().getY()
pass
return False
if ball.k < 0:
for i in range(len(PokemonList)):
try:
if 。。。:
return True
else:
pass
except:IndexError
return False
x = self.image.clone()
x.draw(win)
s=abs(getK())/((getK()**2+1)**0.5)
h=getK()/((getK()**2+1)**0.5)/abs(getK())
while 0 < x.getAnchor().getY() < 600 and 0 < x.getAnchor().getX() < 1000:
if not bump():
x.move(10 * h , 10 * s)
sleep(0.01)
if bump():
## bump()
global web
web = Image(x.getAnchor(),'web.gif')
web.draw(win)
x.undraw()
cover()
print coverList
for i in range(len(coverList)):
if coverList[i].caught():
coverList[i].image.undraw()
x.undraw()
win.bind("<Button-1>",callback)
win.pack()
win.mainloop()
有哪些原因会出现keyerror 展开
1个回答
2016-12-21
展开全部
话说我感觉keyerror只会出现在dictionary里……
我试着运行,发现
if 。。。:
这个也有问题吧。
这个原来是什么?
我试着运行,发现
if 。。。:
这个也有问题吧。
这个原来是什么?
更多追问追答
追问
这个是我程序的一部分。。。因为太长就把他换成了省略号。。。我觉得应该是undraw()调用了tkinter里的方法的时候用了字典,然后才报的错。
追答
我把这行换成if True: 和 if False:
全都没问题,只是什么都不显示。
我用的是Anaconda Spyder
我想知道为什么不需要import?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询