Tkinter python: exceptions for catching

Starting to program in python, I felt at home with an error message. Now, when I program with Tkinter, I find that it often happens that there are errors in my program that I don’t notice, even if they throw an exception: I catch them (sometimes) just because I'm going to debug. Step by step Step (I use wingide) and, for example, on this line I see an exception message. But it annoys me that the program does not stop, but this happens even in blocks not inside try / error.

If what I said makes sense, do you know of a general approach to at least display errors? Being in Tkinter, I can create a window with an error and fill it with any exception if this happens.

+4
source share
2 answers

See the answers to How can I silence exceptions in tkinter , which show how to hook a callback to tkinter.Tk.report_callback_exception .

+7
source

As @ jochen-ritzel said ( Should I make silent exceptions louder in tkinter? ), There is tk.TK.report_callback_exception() that you can override:

 import traceback import tkMessageBox # You would normally put that on the App class def show_error(self, *args): err = traceback.format_exception(*args) tkMessageBox.showerror('Exception',err) # but this works too tk.Tk.report_callback_exception = show_error 
+5
source

All Articles