It is doable but a simpler solution is perhaps to display the exception with a tkinter window. For example, suppose that the program is executed by running a main() function
def main():
print(1 / 0)
main()
You can replace this with
def main():
print(1 / 0)
try:
main()
except Exception:
popup_exception()
The
popup_exception()
function opens a readonly tkinter scrolledtext window showing the error
def popup_exception(title='Error Occurred', label="Exception traceback"):
import tkinter as tk
import tkinter.scrolledtext as st
import traceback
# Creating tkinter window
win = tk.Tk()
win.title(title)
# Title Label
tk.Label(win,
text = label,
font = ("Times New Roman", 15),
background = 'green',
foreground = "white").grid(column = 0,
row = 0)
# Creating scrolled text area
# widget with Read only by
# disabling the state
text_area = st.ScrolledText(win,
width = 80,
height = 25,
font = ("TkFixedFont",
15))
text_area.grid(column = 0, pady = 10, padx = 10)
message = traceback.format_exc()
# Inserting Text which is read only
text_area.insert(tk.INSERT, message)
# Making the text read only
text_area.configure(state ='disabled')
win.mainloop()