python中是否有内置方法(最好是在Tkinter中)运行函数或在设定的持续时间内操作变量?
我想模拟一个圆圈的闪烁..
谢谢!
答案 0 :(得分:0)
Tkinter的Tk有一个后台(预定)功能来电者:Tk.after。它基本上在(m)毫秒后调用你的函数(f):Tk.after(m,f)。所以如果你想让你的圈子眨眼,你可以这样做:
# Mock setup
class Circle:
def __init__(self):
self.on = True
def toggle(self):
self.on = not self.on # Switches from `True` to `False` or `False` to `True`
def draw(...):
...
...
circle = Circle()
root = tkinter.Tk()
def external_toggle_call():
circle.toggle()
circle.draw(...) # Again, pseudo
root.after(100, external_toggle_call) # Recurse after 100 milliseconds
external_toggle_call()
root.mainloop()