Adding Custom C/C++ Drawing Code to Tkinter
March 19, 2002 | Fredrik Lundh
Q. I have a C++ class that draws maps that I’ve been assigned to extend into Python. The class uses X primitive calls (XDrawPoint, etc.) to do much of the work and I’m at a loss on how to integrate this as an extension to Python.
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 WCK 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): _mapwidget.redraw(self.winfo_id(), x0, y0, x1, y1)
In the (hypothetical) _mapwidget extension, use the window handle to get the display (etc) using standard Tk calls.