'How to know if an error has occurred in a tkinter app without a console? [duplicate]

I am working on tkinter project, which the user can't see the console. Is there a way the user can know an error has occurred in the program with out seeing the console.



Solution 1:[1]

messagebox.showerror()

You can use this code for showing error.

Solution 2:[2]

You can add try except statement from the beginning to end of your program, and in except you can use messagebox.showerror to show error.

And for catching the Tkinter error check this answer

But if you want to catch Python errors too for example if index out of range error occur while running a for loop you use

# Note import files before the try statement

from tkinter import *
from tkinter import messagebox 
import sys,traceback
def show_error(slef, *args):
    err = traceback.format_exception(*args)
    messagebox.showerror('Exception',err)
try:
    root=Tk()
    
    Tk.report_callback_exception = show_error
    exec(input()) # Just used to throw error
    a=Button(text='s',command=lambda: print(8/0)) # Just used to throw error
    a.pack()
    root.mainloop()
except BaseException as e:
    messagebox.showerror('Exception',e)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmet Çavdar
Solution 2