3 Aug 2012 19:51
tkinter error handling when tcl calls python functions
Patrick Dunnigan <patrick.dunnigan <at> cloudsidekick.com>
2012-08-03 17:51:35 GMT
2012-08-03 17:51:35 GMT
Hi all,
Scenario:
I am transitioning a mature tcl package to python. As in interim step in the long process, I will use tkinter
in a python script to call the tcl code. Since I have some common functionality already written in python, I
am using the createcommand function to expose this to tcl. As a side note, there is no tk in this software,
only using the tcl piece. Another side note: the useTk=0 argument appears to have no effect.
Everything works nicely. However I have found that when the tcl code calls a python function and an error
occurs in the python, the python error is not included in the tcl error stack. I've spent hours hacking away
trying to figure it out, but now it's time to turn to the community.
Here's a boiled down script that can be used to reproduce and illustrate:
example 1, this is the best message I can get out of tcl, but doesn't include the error that occurs in the
"hello" function:
#!/usr/bin/env python
from Tkinter import Tcl
def hello():
# the error will occur on the following line --->
print z
return
tcl = Tcl()
tcl.createcommand('hello', hello)
try:
tcl.eval('hello')
(Continue reading)
RSS Feed