在不使用函数的情况下替换Tkinter中的while循环

时间:2016-01-04 05:44:09

标签: python while-loop tkinter

有数百个问题涉及Tkinter中的while True:循环(当然会崩溃它,因为它永远不会执行mainloop()(请参阅herehere两个数以百计的例子))。明显的(也是迄今为止唯一的)答案需要某种功能。

我的问题是:有没有办法在Tkinter中有类似于while True:循环的东西没有崩溃,没有使用函数?我没有找到这样的问题。

1 个答案:

答案 0 :(得分:1)

我对python和tkinter不太熟悉,但这应该有效:

import tkinter as tk
import threading

root = tk.Tk()
thread = threading.Thread(target=root.mainloop)
thread.start()

while True:
    print("Hello, World!");
    # TODO - add more stuff to this while loop