Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不使用按钮关闭Python Tkinter窗口主循环_Python_Tkinter - Fatal编程技术网

不使用按钮关闭Python Tkinter窗口主循环

不使用按钮关闭Python Tkinter窗口主循环,python,tkinter,Python,Tkinter,我想每1秒刷新一次python Tkinter窗口: animation=TFS(test) #animation is a list, each item in the list is a table with drawing input information. for item in animation: Display(item) #display function is creating a Tkinter window with a mainloop time.sle

我想每1秒刷新一次python Tkinter窗口:

animation=TFS(test) #animation is a list, each item in the list is a table with drawing input information.
for item in animation:
    Display(item) #display function is creating a Tkinter window with a mainloop
    time.sleep(1)
关于关闭Tkinter的主循环,我在internet上找到的唯一解决方案是在按钮中使用.quit()或.destroy()

但是我不希望用户手动关闭窗口,窗口应该每x秒自动关闭一次,以便能够显示包含更新信息的新窗口


注意:显示器由大约200个矩形和标签组成。

可以在代码中的任何位置调用
.destroy()
方法,而不一定是在按下按钮时调用。要关闭窗口,必须在
Tk
对象(主窗口,您创建的第一个窗口)上调用它。但是,正如前面所说,您不需要关闭窗口来刷新其中的小部件。只需在要修改的小部件上调用
.config()
方法,并将要更改的选项作为参数传递

canva中的显示是程序化的,有数百个形状,因此
.configure
似乎很难使用

因此,我删除了函数显示中的
.mainloop()
,并将其替换为:

TK.update()
time.sleep(RefreshTime)
TK.destroy()
return
并将主代码更改为以下内容:

animation=TFS(test)       
for step in animation:
     Display.display(step,RefreshTime)

您不需要关闭窗口,只需更新其中的数据即可。由于函数Display中的.mainloop(),因此在.sleep(1)之前调用.destroy()或.config()不会成功。