当我使用Tkinter函数时“根.after()“它只运行一次指定的函数。在我的例子中,这是“move”函数,在代码底部的第二行。总的来说,我只是想做一个椭圆形的基本动画。你知道吗
我正在运行python3.7.1。你知道吗
from tkinter import *
class shape:
def __init__(self, canvas):
self.canvas = canvas
self.EdgeThickness = 1
self.color="#ffffff"
def animation(self,xposgiven):
self.shape = self.canvas.create_oval(xposgiven,250,250,400,fill=self.color,width=self.EdgeThickness)
print('runninganimation')
root=Tk()
c=Canvas(root, width=1000, height=500)
c.pack()
c.configure(background="#000000")
s=shape(c)
s.xpos=5
def move():
print('runningmove')
s.xpos+=5
s.animation(s.xpos)
root.after(100,move)
root.mainloop()
我希望函数move()每100毫秒运行一次,但它只运行一次。我认为功能根.after(time,func),每隔'time'毫秒运行函数'func'。但在我的代码中似乎没有这样做。它只运行一次。你知道吗
after
计划作业只运行一次。如果您想让它每100毫秒运行一次,一个常见的策略是在返回函数调用之前将函数调用after
本身作为参数。你知道吗相关问题 更多 >
编程相关推荐