Python GUIs: Abandoning TkInter and welcoming wxPython?

Jeffrey Chang jefftc at leland.Stanford.EDU
Sat Jun 26 02:59:12 CEST 1999


On Fri, 25 Jun 1999, Mikael Lyngvig wrote:
> I'd like some discussion on whether or not it is a good idea to
> abandon TkInter, before it gets too widely used, and instead adopt
> wxPython as the primary GUI framework for Python.

Abandoning Tkinter seems a little bit extreme, since there are some
applications for which its event model is well-suited. 

A few weeks ago I needed to build a viewer that displays binary trees
whose branches have variable lengths (actually, phylogenetic trees for
biological data).  Since the trees are large, I need to be able to slide
it around the window.  In addition, I needed each node to be clickable so
that the user can query for more data. 

Tkinter is very good for that type of thing.  All I needed to do was
create a Canvas and then for each node, create an Oval with a callback to
a function that handles node clicks.  Tk keeps track of the coordinates of
each Item so that I don't have to.  Also, whenever I wanted to move the
tree, all I had to do was:
for widget in self._canvas.find_all():
    self._canvas.move(widget, xoff, yoff)

Of course, Tk incurrs an overhead by making everything you draw on the
canvas its own object, but for this case, it made thigns a lot easier.

Although I haven't used wxWindows before, but the documentation suggests
that it would be a lot more difficult for this kind of application.  In
wxWindows, I would need to draw each of my nodes into a window using a
device context.  Then, I'd have to write a function that would handle
mouse clicks in the window.  That function would need to get the
coordinates and then figure out whether it intersects with any of my
nodes, which Tk would've handled for me.  In addition, whenever I wanted
to move the tree, I'd have to erase the window and redraw each node.  If I
wanted that optimized, I'd need to write routines that would only redraw
the uncovered parts of the tree, which means figuring out which nodes are
newly revealed.

>From what other people have said about wxPython, it seems like it may be
appropriate for other types of applications.  However, I'd hate to see
Tkinter dumped because it's not appropriate for everything!

Jeff





More information about the Python-list mailing list