回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我的目标是实例化一个名为arrow的类,这样我就可以有更多的箭头,而不是1。我想从坐标200开始,每100毫秒增加15个x。但当我尝试执行此代码时,它会给出以下错误:</p>
<pre><code> File "game.py", line 25, in moveArrow
self.after(100, self.moveArrow(arrow, xCoord+15, yCoord)) #repeat, changing x
File "game.py", line 24, in moveArrow
arrow.place(x = xCoord, y = yCoord) #replace with new x,y
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1860, in place_configure
+ self._options(cnf, kw))
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1055, in _options
elif isinstance(v, (tuple, list)):
RuntimeError: maximum recursion depth exceeded while calling a Python object
</code></pre>
<p>“File”game.py“,第25行,在move Arrow self.after(100,self.moveArrow(Arrow,xCoord+15,yCoord))中,重复,更改x“也经常重复。</p>
<pre><code>from Tkinter import *
from random import randint
from PIL import ImageTk, Image
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master, height=400, width=400)
self.master = master
self.master.bind('<Shift_L>', self.createArrow)
def createArrow(self, event):
self.arrow = Arrow(self)
self.arrow.moveArrow(self.arrow, 200, 200)
class Arrow(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.arrowImage = ImageTk.PhotoImage(Image.open("arrow.gif"))
Label(self, image=self.arrowImage).pack()
def moveArrow(self, arrow, xCoord, yCoord):
arrow.place_forget()
arrow.place(x = xCoord, y = yCoord)
self.after(100, self.moveArrow(arrow, xCoord+15, yCoord))
root = Tk()
root.title("Mein erstes Spiel")
app = App(master=root).pack()
root.mainloop()
</code></pre>