Choosing between wxPython and Tkinter.

This is a tread from wiki.wxpython.org.
http://wiki.wxpython.org/index.cgi/Choosing_wxPython_over_Tkinter


Often newbies (including me ;-) ) want to know the differences between Tkinter (the Python included GUI framework) and the add-on wxPython framework. Here's the consensus of people in mailing list:

David Woods:

* wxPython is easier to work with than Tkinter. You can get things up and running more easily and with less "voodoo" code.
*

Both platforms claim to be cross-platform, but both still have issues on Mac OS-X, a platform I must support. In my (admittedly somewhat superficial) evaluation, wxPython, through MachoPython, seems more stable and more workable on Mac OSX. It seems more cross-platform-ish, at least as far as Mac development goes.
*

In my perception, wxPython is a rising tool with an active development community, while Tcl/tk and Tkinter are old, worn out, and falling out of favor. It strikes me as the tool of the future, the one with the momentum.

Cliff Wells:

wxPython (used interchangeably with wxWidgets for this discussion) and Tkinter take two different approaches to cross-platform compatibility. wxPython recognizes that most GUIs have very similar features but widely vary in the API used to access them. As such it provides a wrapper around the native GUI so as to provide a common API on all platforms. The advantage of this is a native look-and-feel for wxPython apps. A wxPython app running on Windows looks like any other Windows app. The *same* application running on GNOME will look like any other GNOME app (including picking up the default theme).

Tkinter takes an entirely different approach. Rather than rely on the native widget set, Tkinter solves the cross-platform problem by implementing its *own* from scratch, using the drawing primitives available on each platform. The downside to this is that Tkinter apps tend to look like misfits on every desktop. I can tell just by looking at a screenshot if a program was written using Tkinter.

Pros and Cons of each

For the developer, there are several things to consider:

Tkinter

Pros:

1. Mature, stable.
2. Widely ported.
3. De facto default GUI toolkit for Python (included with distro).
4. Simple API is easy to learn.

Cons:

1. Non-native look-and-feel.
2. Simplistic model is easy to learn, but becomes cumbersome with complex interfaces.
3. To be truly usable, requires downloading extra toolkits (PMW for example).
4. Probably a dead-end technology, as toolkits such as wxPython gain mindshare.

wxPython

Pros:

1. Large library of widgets
2. Native look-and-feel.
3. Very flexible.
4. Very helpful user community (which you've found =)

Cons:

1.

Very active development (although this is a pro as well ;) ) means that there are quite often bugs and, less often, API changes.
2. Requires downloading and installing (not included with Python).
3.

Once you start using it, you'll find yourself evangelizing as much as you program ;)

And Again by Cliff:

Yes, with wxPython you pay the price up front, in the learning curve. With Tk you pay it later, when you're developing applications with real interface requirements.

Will Sadkin injected his experiences:

* There are GUI development environments available for it, (eg. wxDesigner, boa constructor, and reportedly others), making it easier to construct, tweak and maintain applications over time. (We use wxDesigner.)
* The resulting applications loaded and appeared much more quickly (at least under MSW), presumably due to the native implementation details.
* There's a great store of usage examples in the wxPython demo (thanks to Robin Dunn et. al!) that help you figure out the tricky bits for most GUI elements, included as part of the distribution. While not a substitute for written documentation, I'd rather examine working code than pour over a tome to do this any day!
*

The users group is one of the most attentive, responsive and helpful communities I've ever run across on the net, and the signal to noise ratio has remained quite high over the time that I've been following it. (Kudos to all of you, and particularly to Robin, who is just phenomenal!)

There was also a consensus that the "native Tk look" was being done through some native work and some work within the library to make things look right.

One of the features not listed that I think might be important is that wxPython can be used with wxWidgets as a RAD (Rapid Application Development) tool. Things will look similar if you want to go C++ for speed/size issues.

Also available is a page from 'Python Programming on Win32', from O'Reilly which goes into much greater detail than we have here and compares Tkinter, PythonWin and wxWidgets (formerly known as wxWindows).

Comments...

I would love to see a comparison between wxPython and PyQt. Is there not anyone out there who has used both toolkits for real work who can write a page like this, but for wxPython vs. PyQt?

--Jan Persson

I'll create ComparingWxPythonAndPyQt for this purpose.

Should we add that one of the Pros of Tkinter is the Canvas widget? I am working on a medium size Python application (15K+ lines) and I use the Canvas widget extensively. Recently wanted to refactor the GUI and perhaps switch from Tkinter to wx or PyGTK but I still have not found any widget that is as powerful as the Tkinter's Canvas in the wx toolkit. --Nick Vatamaniuc


回复

此内容将保密,不会被其他人看见。
  • 允许的 HTML 标签: <a> <em><img> <strong> <cite> <code> <small> <table> <th> <tr> <td> <ul> <ol> <li> <dl> <dt> <dd> <hr>
  • 行和段被自动切分。
  • 网页地址和电子邮件地址将会被自动转换为链接。
  • Images can be added to this post.

更多格式化选项信息