I have a visualization tool written in Tkinter. Typically, I execute it standalone and then manually close the window when I'm finished. However, I'd like to be call it from another Python program, execute the main loop once (and save the canvas as an SVG), and then close the window, allowing the program to continue.
If I could not even bother opening a window, but just re-use my code to draw an SVG, that would work too.
My tk application looks like this:
class MainApplication(tk.Frame):
def __init__(self, output_path, parent=None):
tk.Frame.__init__(self, parent)
self.parent = parent
# draw visualization, save as svg
#...
#
From another part of my code, I call the
kill = True
root = tk.Tk()
root.title("Placement Visualizer")
MainApplication(output_path, root ).pack(side="top", fill="both", expand=True)
if kill:
root.destroy()
root.mainloop()
I get this error: Tcl_AsyncDelete: async handler deleted by the wrong thread Aborted (core dumped)
I've tried using root.quit() or removing root.mainloop(), but I don't get the desired result.
Thank you