Python Forum
console pwd file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: console pwd file (/thread-36013.html)



console pwd file - kucingkembar - Jan-09-2022

hi, sorry for my bad English,
is there any way to run the PWD file,
but if something happens like an error,
the "console" (what this is called? console? shell?) will open,
then it will show the error log (Traceback log) like a normal PW file,
is this doable?


RE: console pwd file - ndc85430 - Jan-09-2022

I don't understand your question. What do you mean by "the PWD file"?


RE: console pwd file - kucingkembar - Jan-09-2022

sorry typo
pyw file


RE: console pwd file - Gribouillis - Jan-09-2022

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()



RE: console pwd file - kucingkembar - Jan-09-2022

thank you Gribouillis,
this is what i looking for,
I will give you reputation point