我正在尝试学习如何在终端中工作时托管第二个帮助程序窗口来托管一些数据。其中一部分涉及定期更改窗口的内容,我希望第二个窗口不要阻塞主进程。因此,我希望能够以线程启动tkinter文本。
以下是我目前所拥有的。首次调用启动线程时,将显示tkinter文本框,一旦关闭,线程将加入。在第二次启动时,未创建该窗口,您可以看到从未调用过“启动后”。有人知道我在做什么错吗?谢谢!
>>> import threading
>>> import tkinter as tk
>>> def build_textbox():
root = tk.Tk()
T= tk.Text(root, height=100, width=100)
T.pack()
T.insert(tk.END, "Hello World")
tk.mainloop()
>>> def launch_thread():
print("Function called")
thread = threading.Thread(target=build_textbox)
print("Thread created")
thread.start()
print("After start")
thread.join()
print("Success")
>>> launch_thread()
Function called
Thread created
After start
Success
>>> launch_thread()
Function called
Thread created