I was trying to implement a GUI for an existing program that was controlled through the Keyboard. So I started with using Tkinter.
However, as I was searching and trying for solutions, I realized that in order for my Tkinter GUI program needs to run along side my original program I need multi-threading. Since I did not want to change too much of the original program, risking creating more complicated bugs, I tried to run the program on the main thread and GUI on a created thread.
As a result, I kept getting this error
Tcl_AsyncDelete: async handler deleted by the wrong thread
Aborted (core dumped)
And this is my tester code:
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()
I read from other sites that it will be better to use the Tkinter thread as the main thread but that would cause many changes to the original program, which I am reluctant to do.
Thanks!