tkinter root.mainloop with While True loop

左心房为你撑大大i 提交于 2019-12-02 06:34:15

Tkinter needs mainloop to work (to call all functions behind).
Use root.after(time_ms, function_name_without_() ) (before mainloop)
to run some function - and that function have to run the same after(...) to work in loop.

In Tkinter you don't use while True because while True is to make (main)loop
but Tkinter has own mainloop.

And don't use sleep() - use after()

Put all code from while True (except mainloop) in some function and call it using after().
Use second after() in place of sleep().

import Tkinter as tk

master = tk.Tk()

def my_mainloop():
    print "Hello World!"
    master.after(1000, my_mainloop)    

master.after(1000, my_mainloop)

master.mainloop()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!