0

I have a problem:
How to insert raise in Text()?
for example i have file:

#my_program.py
a=ddd

and other file:

#my_file.py:
from Tkinter import*
root=Tk()
text=Text()
text.pack()
execfile('my_program.py')
#text.insert(END,raise)
mainloop()

In file my_program is Error. How to insert raise of this error in Text?

thanks

2
Contributors
1
Reply
3
Views
10 Years
Discussion Span
Last Post by Ene Uran
0

You can use function sys.exc_info() to fetch the error created by my_program.py:

# save as my_file.py
# executes a file my_program.py which has an error

from Tkinter import*
import sys

root=Tk()
text=Text()
text.pack()

try:
    execfile('my_program.py')
except:
    error = "%s --> %s in file my_program.py"% (sys.exc_info()[0], sys.exc_info()[1])
    
# put error msg raised by my_program.py into text field
text.insert(END, error)
mainloop()

I am always surprised by the things Python can do! Have fun with Python!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.