On Fri, Apr 29, 2005 at 11:01:15AM -0600, David King wrote:
> But let's leave WCK aside and just talk about plain Tkinter for the moment.
> I'd like to understand how my custom C++/Tk widget could make itself known
> in the usual Tkinter world. On the C++ side, essentially all my Tcl/Tk API
> calls interact with a tcl interpreter handle ('Tcl_Interp*'). Presumably I
> need to get the one Tkinter uses, instead of creating an interpreter myself
> (and also to let Tkinter handle the event loop, rather than doing _that_
> myself). I'm wondering how I get this handle from Tkinter.
Here is some "C" code that I have used for this purpose.
// this code is in the public domain
static Tcl_Interp *get_interpreter(PyObject *tkapp) {
long interpaddr;
PyObject *interpaddrobj = PyObject_CallMethod(tkapp, "interpaddr", NULL);
if(interpaddrobj == NULL) { return NULL; }
interpaddr = PyInt_AsLong(interpaddrobj);
Py_DECREF(interpaddrobj);
if(interpaddr == -1) { return NULL; }
return (Tcl_Interp*)interpaddr;
}
'PyObject *tkapp' is the thing returned by _tkinter.create(), and available as
the 'tk' attribute on all Tkinter widgets.
This is not foolproof, because passing in an object like
class K:
interpaddr = 0
will soon lead to a crash. But if you can trust the calling code to only pass
in
"real" interpreters, it should work just fine.
Jeff
pgpOq4rwFSs2G.pgp
Description: PGP signature
_______________________________________________ Tkinter-discuss mailing list [email protected] http://mail.python.org/mailman/listinfo/tkinter-discuss
