Whenever I get an error in my Tkinter application, I would like to get a full stack trace of where the error occurred, through all of the functions the program is currently in.
Before my root window opens, I have Tk.report_callback_exception = TKINTERERROR and I am able to get the traceback object of the error in TKINTERERROR(). However, when I attempt to print the traceback (with traceback.format_list(traceback.extract_tb(tracebackObject))), it only gives me the most recent function call, and the line the error occurred on. Is this all that is possible with Tkinter exceptions, or is there a way to get the entire stack trace?
To elaborate, what I expect to get is something like this, in which all the functions the program is currently in are given:
Traceback (most recent call last):
File "myfilepath", line 13, in <module>
func1()
File "myfilepath", line 2, in func1
func2()
File "myfilepath", line 5, in func2
func3()
File "myfilepath", line 8, in func3
func4()
File "myfilepath", line 11, in func4
0/0
ZeroDivisionError: division by zero
However, I actually only get this:
File "...Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "myfilepath.py", line 1898, in <lambda>
widgetMethod(arguments, command = lambda: MyFunction(arguments))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "myfilepath", line 2465, in MyFunction
0/0
~^~
My problem is that I would like to get the full stack trace, but I am only given the most recent function called.
tkintercalls my function. What do you expect thetracebackto look like? Can you give an example of what you are getting vs what you expect to get? On a side note, if you want to simplify your code a bit, use this..bind/.trace/.after,tkinterwill call your code from inside themainloop().tkinterremoves all of traceback that comes from you calling the.mainloop(). Right now it looks like you have a button which callsMyFunctionwithargumentsand inside there you have are trying to divide by 0..mainloop(), as my example is an error from aToplevel()window?tkinterdoes run from another thread. Also you should only have 1.mainloop()in your code (no matter how manyTk()/Toplevel()widgets you have). Therefore, there's no point in showing the traceback for the.mainloop().