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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.