Extending Python/Tkinter

Fredrik Lundh fredrik at pythonware.com
Tue Mar 19 15:27:00 EST 2002


Cris Eck wrote:

> Initially I thought  I could get a drawable, display and graphics
> context from the Tk C API.  Then I saw that Tkinter is using the
> Tcl interpreter and not calling the Tk routines directly.

well, the fact that there's a Tcl interpreter involved doesn't
mean that you won't end up in the Tk library when it's time
to draw something...

one way to implement this is to use the Tkinter 3000 WCK to
take care of the Tkinter interface bit, and call your widget code
from relevant ui_handle methods, e.g:

# tkinter 3000 framework
from tk3 import Widget

# import map widget driver
import _mapwidget

class MapWidget(Widget):
    def ui_handle_resize(self, width, height):
        _mapwidget.resize(self.winfo_id(), width, height)
    def ui_handle_repair(self, draw, x0, y0, x1, y1):
        window = self.winfo_id()
        _mapwidget.redraw(self.winfo_id(), x0, y0, x1, y1)

in the _mapwidget extension, use the window handle to get
the display (etc) using ordinary Tk calls.

more info here: http://effbot.org/tkinter

</F>





More information about the Python-list mailing list