我听说Python中的线程不容易处理,他们变得更加纠结于tkinter。线程和tkinter python 3
我有以下问题。我有两个类,一个用于GUI,另一个用于无限过程。首先,我启动GUI类,然后启动无限过程的类。我希望当你关闭GUI时,它也完成了无限的过程,程序结束。
代码的简化版本如下:
import time, threading
from tkinter import *
from tkinter import messagebox
finish = False
class tkinterGUI(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global finish
#Main Window
self.mainWindow = Tk()
self.mainWindow.geometry("200x200")
self.mainWindow.title("My GUI Title")
#Label
lbCommand = Label(self.mainWindow, text="Hello world", font=("Courier New", 16)).place(x=20, y=20)
#Start
self.mainWindow.mainloop()
#When the GUI is closed we set finish to "True"
finish = True
class InfiniteProcess(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global finish
while not finish:
print("Infinite Loop")
time.sleep(3)
GUI = tkinterGUI()
GUI.start()
Process = InfiniteProcess()
Process.start()
当我点击关闭按钮(在右上角)出现在控制台以下错误:
Tcl_AsyncDelete :异步处理程序由错误的线程删除
我不知道它为什么发生或它的意思,请帮助!
您的简历版适用于我...必须有一些你忘记添加,这是导致你的问题 – mguijarr 2014-11-02 19:52:30
@mguijarr我在谷歌阅读,这个错误是更常见的窗口,你的SO?我的是Windows 7 x64。也许窗口是问题:/ – 2014-11-02 20:14:50