我试图每 1 秒更改一次矩形的颜色,由于某种原因,只使用最后一种颜色。中间的那些根本不用。我在哪里做错了?这是我的代码 -
class app():
def __init__(self):
self.root = Tk()
self.root.minsize(500, 500)
self.root.maxsize(500, 500)
self.counter = 4
self.color = ["red","green","yellow","grey"]
self.mainframe = Canvas(self.root, width=400, height=200)
self.blue = self.mainframe.create_rectangle(20,20,120,60,fill='blue',width=0)
self.mainframe.pack()
Button(self.root,text="press",command=self.click).pack()
self.root.mainloop()
def click(self):
self.root.after(1000,self.__timer)
def __timer(self):
if self.counter > 0:
for i in range(self.counter):
self.mainframe.itemconfigure(self.blue_button,fill=self.color[i])
self.root.after(1000,self.__timer)
self.counter -= 1