Python:与程序一起作为控制器运行的GUI

时间:2016-06-18 00:00:54

标签: python multithreading user-interface tkinter runtime-error

我正在尝试为通过键盘控制的现有程序实现GUI。所以我开始使用Tkinter。

然而,当我在搜索和尝试解决方案时,我意识到为了让我的Tkinter GUI程序需要与原始程序一起运行,我需要多线程。由于我不想改变太多的原始程序,冒着创建更复杂的错误的风险,我试图在创建的线程上的主线程和GUI上运行程序。

结果,我不断收到此错误

  

Tcl_AsyncDelete:错误线程删除的异步处理程序

     

中止(核心倾销)

这是我的测试代码:

from Tkinter import *
from GUI_interface import *
import threading
import time

class guiThread (threading.Thread):
    def __init__(self, inc):
        threading.Thread.__init__(self)
        self.inc = inc
        self.start()

    def run(self):

        # initializing GUI interface
        self.root = Tk()
        self.root.geometry("600x300+500+500")
        self.myGUI = Example(self.root, self.inc)

        self.root.mainloop()
        self.root.quit()
        self.__del__()

    def __del__(self):
        print "now I'm dead"

def main():
    global_header.init()
    my = guiThread(4)

    while 1:
        time.sleep(2)
        print my
        if not my.isAlive():
            my = None
            break;
        print "%d" % global_header.t

if __name__ == "__main__":
    main()

我从其他网站上读到,最好使用Tkinter线程作为主线程,但这会导致原始程序发生很多变化,我不愿意这样做。

谢谢!

0 个答案:

没有答案