【发布时间】:2018-01-07 07:41:07
【问题描述】:
我想在 Tkinter 中制作一个画布,它应该每隔一秒移动一次。 我已经写了这段代码。
import time
from tkinter import *
root = Tk()
root.geometry('800x800')
c = Canvas(root, width=500, height=500)
c.config(bg='#00f')
c.place(x=0)
y = 0
while True:
print(y)
c.place(x=y)
y -= 50
if y < -500:
break
time.sleep(1)
root.mainloop()
在这里,我使用 While Loop 制作动画,其中每 1 秒后,A Blue Canvas 将移动到 -ve x 轴.
它正在按我的意愿移动,但窗口在动画之后出现(因为我在 While 循环之后使用了 root.mainloop()),我不能使用 root.mainloop() 在 While Loop 之前,因为它会给出错误。
有没有其他方法可以让动画只在创建窗口后才运行?
【问题讨论】:
标签: python python-3.x animation tkinter tkinter-canvas