Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
console pwd file
#1
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?
Reply
#2
I don't understand your question. What do you mean by "the PWD file"?
Gribouillis likes this post
Reply
#3
sorry typo
pyw file
Reply
#4
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()
kucingkembar likes this post
Reply
#5
thank you Gribouillis,
this is what i looking for,
I will give you reputation point
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Save console output to text file (like a log) koticphreak 9 29,372 Jun-02-2019, 07:45 PM
Last Post: snippsat
  python console executes a file that PyCharm cannot execute sylas 6 5,257 Jun-10-2017, 04:50 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020