我的目標是實例化一個名爲箭頭的類,所以我可以有更多的箭頭,然後只是1.我想從座標200,200開始,並且希望將x增加15每100毫秒。但是,當我嘗試執行此代碼它給我以下錯誤:調用Python對象時超出最大遞歸深度
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
「文件 「game.py」 25行,在移動箭頭self.after(100,self.moveArrow(箭頭,XCOORD + 15,yCoord))#repeat,改變x「也經常重複。
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()
http://effbot.org/tkinterbook/photoimage.htm < - 如果你對圖像有問題,特別是關於如何保留參考底部的註釋,請看看。我只用一個文本標籤進行測試。 – atlasologist
這裏有很多很好的信息:http://effbot.org/tkinterbook/tkinter-index.htm ...除此之外,只是做東西,你會發現它 – atlasologist