Tkinter and C extensions

Andrew MacIntyre andymac at bullseye.apana.org.au
Thu Apr 6 06:44:41 EDT 2000


On 6 Apr 2000, Bernhard Herzog wrote:

> Andrew MacIntyre <andymac at bullseye.apana.org.au> writes:
> 
> [...]
> > My research has turned up ways of determining these via Tk's API
> > (Tk_Display(), Tk_Window() in tk.h) provided I can extract the tkwin
> > handle from Tkinter's canvas widget - something I've yet to figure out how
> > to do from within a C extension.
> > 
> > I'm wondering whether its possible to get at this information via Tkinter,
> > which would simplify the interactions between the various components.
> 
> Tkinter widgets have a tk attribute which is basically a tcl
> interpreter. It's interpaddr() method returns the TclInterp* pointer as
> a python int object. Just pass that and the name of the widget to a
> C-extension function and the rest follows from that...

Thanks for this thought - it fills in another gap.

After more research and another read of Fredrik's Tkinter docs, I've
reached the conclusion that its only the X Display pointer thats a problem
- the Window handle is available from the widget's winfo_id() method.  Oh,
and a Frame would be better than a Canvas for the intended purpose too.

AFAICT the only way to convert a widget's name to a pointer to its
Tk_Window structure, so that the Display pointer can be retrieved, 
requires a pointer to _another_ Tk_Window structure in the same widget
tree :-( Somewhat of a recursive problem when just one such pointer would
probably give me the info I require....

This is probably one of the very few situations where Tkinter's "arms
length" usage of Tk is an impediment.

I've still a couple of ideas to follow up though....

> > Any hints on additional sources of enlightment, such as other modules
> > which have similarities, would be appreciated.
> 
> Sketch's paxmodule does something similar. Sketch uses it to implement
> widgets in Python, which allow you to handle expose events yourself and
> use Xlib functions to draw the widgets.

Thanks for this suggestion as well.

BTW, it was SVGAmodule rather than GDmodule whose link from the Vaults of
Parnassus led to a dead end.

--
Andrew I MacIntyre                     "These thoughts are mine alone..."
E-mail: andrew.macintyre at aba.gov.au    (work) | Snail: PO Box 370
        andymac at bullseye.apana.org.au  (play) |        Belconnen  ACT  2616
        andymac at pcug.org.au           (play2) |        Australia





More information about the Python-list mailing list