Tkinter vs wxPython: your opinions?

Neil Cerutti cerutti at together.net
Fri Jan 26 08:35:51 EST 2001


Cameron Laird posted:
>In article <slrn9710o1.73.cerutti at fiad06.norwich.edu>,
>Neil Cerutti <cerutti at together.net> wrote:
>>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.
>
>It's very typical that Tkinter people who try moving to other
>toolkits blanch and retch at the "placing" they have to do.
>Tkinter layout management is addictive.

One thing I left out is comparison of available IDE building
editors, which could easily make this a moot point. I love the
conceptual space created in Tkinter between creating a widget and
telling it where and how to appear on the screen. A lot of the
wxPython widgets must appear at the time of creation.

>>wxPython has access to more standard interface dialogs, though
>>Tkinter has a fair number, too. The wxPython GUI code is going
>>to be quite a bit shorter. It would probably lengthen if I
>>started using a layout manager.
>
>This paragraph lost me.  Are you saying your Tkinter source is
>longer because you have to construct for yourself dialogues
>which are standard in wxPython?  Are you further saying that
>using a layout manager in wxPython is *more* verbose than pixel
>placement in wxPython?

Actually, yes. Pixel placement is so crude, it takes up hardly
any space. And you don't need to provide nearly as many options
to wxPython objects as you do a Tkinter widget. For example, the
wxPython ListBox is much more concise than the Tkinter Listbox,
especially if a you need a scroll bar. At the risk of further
revealing myself to be a total tyro, here's list box code for you
to compare from my sample programs.

Tkinter:

(Keep in mind, there is no way on earth I could have figured out
how to add a scroll bar if not for the pythonware docs.)

    sb = Scrollbar(self.upperFrame)
    self.newsServerListbox = Listbox(self.upperFrame, 
      height=3,
      yscrollcommand=sb.set,
      bg="SystemWindow")
    for server in self.servers:
      self.newsServerListbox.insert(END, server)
    self.newsServerListbox.select_set(0)
    self.newsServerListbox.pack(side=LEFT)
    sb.pack(side=LEFT, fill=Y)
    sb.config(command=self.newsServerListbox.yview)
    self.newsServerListbox.bind ("<Button-3>", self.popUp)

I had to set bg to make the list box look normal for a Windows
app, and that using the scrollbar was baroque. The pack layout
manager requires lots of extra frame object for the best
performance.

The same list box in wxPython:

    self.newsServerListBox = wxListBox(panel, -1, 
      wxPoint(5, 15), wxSize(140, 54),
      [], wxLB_SINGLE)
    for server in self.servers:
      self.newsServerListBox.Append(server)
    self.newsServerListBox.SetSelection(0, true)
    EVT_RIGHT_DOWN(self.newsServerListBox, self.popUp)

Here, it looks good out of the gate, and includes a vertical
scroll bar by default if the listbox is too big. The Tkinter
widget scroll bar appears, even when it doesn't need to be there
though that can probably be fixed.

I forgot to mention the ID members of wxPython objects, which are
unintuitive when it seems so simple to use actual objects in
function calls instead. I can see how secret ID nos could
save stack space and pointer passing in a C++ program.

-- 
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