import tkinter as tk

def go():
    try:
        raise Exception("Test error")
    except Exception as e:
        import traceback
        with open("error.log", "w") as f:
            f.write(traceback.format_exc())

root = tk.Tk()
tk.Button(root, text="Go", command=go).pack()
root.after(100, go)
root.after(500, root.destroy)
root.mainloop()
