Tkinter vs wxPython: your opinions?

Robin Dunn robin at alldunn.com
Thu Jan 25 17:39:47 EST 2001


"Neil Cerutti" <cerutti at together.net> wrote in message news:slrn9710o1.73.cerutti at fiad06.norwich.edu...
> 
> For comparison purposes, I'm writing my first GUI app, a simple
> wrapper for slrn, in Tkinter and wxPython.
> 
> Tkinter's 'pack' layout manager is super easy to use, and with
> some practice and the excellent documentation, powerful. wxPython
> seems to have a couple of layout managers, but how they should be
> used is a mystery. I've been forced to place everything pixel by
> pixel so far.

Look at the docs and demo for wxSizer and it's derived classes.  It's by far the easiest mechanism available in wxPython, and nearly as powerful as wxLayoutConstraints.

> 
> wxPython is supposed to be faster, but it isn't for the tiny app
> I've written, because it takes nearly 3 times as long to get
> started.

Because it's loading and initializing 10 times as much code!  (I'm working on ways to streamline the initial set of stuff needed to get started, and also to limit the additional DLLs loaded by this initial set...)


> 
> Binding widgets to callbacks in Tkinter is much easier for me to
> understand than the wxPython EVT_ macros. Tkinter's events seem
> much easier to bind, since I don't have to worry about which
> widget generates what event -- they all seem to generate everything
> I've wanted to bind. In wxPython, I haven't figured out how to
> get my app to close if I hit ESC. Nothing I've tried EVT_CHARing
> has bothered to actually generate an event.

EVT_CHAR, EVT_KEY_DOWN, and EVT_KEY_UP only get events when bound to the window or control with the keyboard focus, so it's not what you do if you want to have an application-wide command bound to a key.  Even when dealing with char or key events on the focused window special keys like ESC are sometimes snached by other windows in order to do navigation and things.

What you probably want is an accelerator, which is a way to tell the system to intercept keys and generate menu events from them.  For example, making the text for a menu item like this, "E&xit\tAlt-X" will make the Alt-X key generate the same event that selecting the menu item does.  You can also do accelerators without menu items, and for the ESC key I think you need to do it this way:

    aTable = wxAcceleratorTable([ (wxACCEL_NORMAL,  WXK_ESCAPE, ID_CLOSEAPP) ])
    self.SetAcceleratorTable(aTable)
    EVT_MENU(self, ID_CLOSEAPP, self.OnCloseApp)


> 
> The objects in wxPython are more full-featured (I guess--for some
> definition of full featured), but aren't as easily configurable
> as the Tkinter ones. For example, in Tkinter, I've bound
> right-clicking to a list box of news servers. A popup menu allows
> me to remove that new server from the list, or add another one. I
> can catch a EVT_RIGHT_BUTTON in wxPython, but I can't (so far)
> find out which list item the pointer was near when the event
> occurred. (For that matter, I can't make a popup menu either yet
> either, though I *know* it's possible. It says in the
> documentation that a Menu can be a popup.)

See the wxListCtrl demo.


> 
> wxPython's documentation seems to be in the state Tkinter's was
> back when all there was was the _Tkinter life preserver_.

I hope to rectify this over the next few months.  Lack of Python specific documentation has always been an issue, and it is now getting near the top of my must-have list.

> 
> Better advice is probably to try them both for some small sample
> app, like I have, and make up your own mind.  

This is my recommendation as well.  My experience is that some people have a natural ability to pick up and understand wxPython and Tkinter seems mind boggling strange or complex to them.  For others it is completely opposite, they grok Tkinter just fine, but "just don't get" wxPython.  Personally I think that this means that there are two incompatible ways that Pythoneer's brains are wired, but I could be wrong.  I suppose that a "wxPython for Tkinter Programmers" document would be useful, but my brain is wired wrong so I couldn't write it.  <wink> 


hold-your-brain-up-to-the-scanner-please-ly y'rs,

-- 
Robin Dunn
Software Craftsman
robin at AllDunn.com       Java give you jitters?
http://wxPython.org      Relax with wxPython!


> -- 
> Neil Cerutti <cerutti at together.net>
> "If you're gonna score 125 points in a game, you've only got to
> play good enough defense to hold the other team to 124. How
> the hell hard is that?" -- Red Auerbach




More information about the Python-list mailing list