用于部署Python应用程序的跨平台gui工具包

时间:2023-01-24 12:10:13

Building on: http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/

建立在:http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/

Merits:

1 - ease of design / integration - learning curve

1 -易于设计/集成-学习曲线

2 - support / availability for *nix, Windows, Mac, extra points for native l&f, support for mobile or web

2 -支持*nix, Windows, Mac,本地l&f的额外积分,支持移动或web

3 - pythonic API

3 -神谕的API

4 - quality of documentation - I want to do something a bit more complicated, now what?

文档质量——我想做一些更复杂的事情,现在怎么办?

5 - light weight packaging so it's not necessary to include a full installer (py2exe, py2app would ideally work as-is and not generate a gazillion MBs file)

5 -轻量级包装,所以不需要包含完整的安装程序(py2exe, py2app理想的工作是按原样工作,而不是生成一个gazillion MBs文件)

6 - licensing

6 -许可

7 - others? (specify)

7 -其他人呢?(指定)


Contenders:

1 - tkinter, as currently supported (as of 2.6, 3.0)

1 - tkinter,目前支持(从2.6,3.0开始)

2 - pyttk library

2 - pyttk图书馆

3 - pyGTK

3 - pyGTK

4 - pyQt

4 - pyQt

5 - wxPython

5 - wxPython

6 - HTML-CGI via Python-based framework (Django, Turbogears, web.py, Pylons...) or Paste

6 - HTML-CGI通过基于python的框架(Django, Turbogears, web)。py,塔…)或粘贴

7 - others? (specify)

7 -其他人呢?(指定)

5 个解决方案

#1


43  

Please don't hesitate to expand this answer.

请毫不犹豫地扩展这个答案。

Tkinter

Tkinter is the toolkit that comes with python. That means you already have everything you need to write a GUI. What that also means is that if you choose to distribute your program, most likely everyone else already has what they need to run your program.

Tkinter是python自带的工具包。这意味着您已经拥有了编写GUI所需的一切。这也意味着,如果您选择发布您的程序,那么很可能其他人都已经拥有了运行您的程序所需的内容。

Tkinter is mature and stable, and is (at least arguably) quite easy to use.I found it easier to use than wxPython, but obviously that's somewhat subjective.

Tkinter是成熟和稳定的,并且(至少可以说)非常容易使用。我发现它比wxPython更容易使用,但显然这有点主观。

Tkinter gets a bad rap for looking ugly and out of date. While it's true that it's easy to create ugly GUIs with Tkinter, it's also pretty easy to create nice looking GUIs. Tkinter doesn't hold your hand, but it doesn't much get in the way, either. Tkinter looks best on the Mac and Windows since it uses native widgets there, but it looks OK on linux, too.

Tkinter因外表丑陋和过时而受到批评。虽然用Tkinter创建难看的gui很容易,但是创建漂亮的gui也很容易。Tkinter并没有握住你的手,但是它也不会阻碍你。Tkinter在Mac和Windows上看起来是最好的,因为它使用了本地的小部件,但是在linux上看起来也不错。

The other point about the look of Tkinter is that, for the most part, look isn't as important as people make it out to be. Most applications written with toolkits such as Tkinter, wxPython, PyQT, etc are special-purpose applications. For the types of applications these toolkits are used for, usability trumps looks. If the look of the application is important, it's easy enough to polish up a Tkinter application.

关于Tkinter外观的另一个观点是,在大多数情况下,外观并不像人们想象的那么重要。大多数使用工具包(如Tkinter、wxPython、PyQT等)编写的应用程序都是特殊用途的应用程序。对于这些工具包用于的应用程序类型,可用性优于外观。如果应用程序的外观很重要,那么就很容易改进Tkinter应用程序。

Tkinter has some features that other toolkits don't come close to matching. Variable traces, named fonts, geometry (layout) managers, and the way Tkinter processes events are still the standard to which other toolkits should be judged.

Tkinter有一些其他工具包无法匹配的特性。变量跟踪、命名字体、几何(布局)管理器和Tkinter处理事件的方式仍然是判断其他工具包的标准。

On the downside, Tkinter is a wrapper around a Tcl interpreter that runs inside python. This is mostly invisible to anyone developing with Tkinter, but it sometimes results in error messages that expose this architecture. You'll get an error complaining about a widget with a name like ".1245485.67345" which will make almost no sense to anyone unless you're also familiar with how Tcl/tk works.

缺点是,Tkinter是一个在python中运行的Tcl解释器的包装器。对于使用Tkinter开发的任何人来说,这几乎是不可见的,但它有时会导致暴露此架构的错误消息。您将会得到一个错误,抱怨一个名为“.1245485.67345”的小部件,这对任何人都没有意义,除非您还熟悉Tcl/tk的工作方式。

Another downside is that Tkinter doesn't have as many pre-built widgets as wxPython. The hierarchical tree widget in Tkinter is a little weak, for example, and there's no built-in table widget. On the other hand, Tkinter's canvas and text widgets are extremely powerful and easy to use. For most types of applications you will write, however, you'll have everything you need. Just don't expect to replicate Microsoft Word or Photoshop with Tkinter.

另一个缺点是Tkinter没有wxPython那么多预先构建的小部件。例如,Tkinter中的层次树小部件有点弱,而且没有内置的表小部件。另一方面,Tkinter的canvas和文本小部件非常强大,易于使用。然而,对于您将要编写的大多数类型的应用程序,您将拥有所需的一切。不要指望用Tkinter复制Microsoft Word或Photoshop。

I don't know what the license is for Tkinter, I assume the same as for python as a whole. Tcl/tk has a BSD-style license.

我不知道Tkinter的许可是什么,我假设python作为一个整体是一样的。Tcl/tk具有bsd样式的许可证。

PyQt

It's build on top of Qt, a C++ framework. It's quite advanced and has some good tools like the Qt Designer to design your applications. You should be aware though, that it doesn't feel like Python 100%, but close to it. The documentation is excellent

它构建在Qt之上,Qt是一个c++框架。它非常先进,并且有一些很好的工具,比如Qt设计器来设计应用程序。不过,您应该知道,它感觉不像100%的Python,但接近于它。文档是优秀的

This framework is really good. It's being actively developed by Trolltech, who is owned by Nokia. The bindings for Python are developed by Riverbank.

这个框架真的很好。诺基亚旗下的Trolltech公司正在积极开发这款手机。Python的绑定是由Riverbank开发的。

PyQt is available under the GPL license or a commercial one. The price of a riverbank PyQt license is about 400 euro per developer.

PyQt可以通过GPL许可或商业许可使用。河岸的PyQt许可证的价格大约是每个开发商400欧元。

Qt is not only a GUI-framework but has a lot of other classes too, one can create an application by just using Qt classes. (Like SQL, networking, scripting, …)

Qt不仅是一个gui框架,而且还有很多其他类,您可以通过使用Qt类来创建应用程序。(比如SQL、网络、脚本等等)

Qt used to emulate GUI elements on every platform but now uses native styles of the platforms (although not native GUI toolkits): see the documentation for Mac OS X and the windows XP style

Qt曾在每个平台上模拟GUI元素,但现在使用了平台的本地样式(尽管不是本地GUI工具包):请参阅Mac OS X和windows XP样式的文档

Packaging is as simple as running py2exe or pyInstaller. The content of my PyQt app looks like this on windows (I have used InnoSetup on top of it for proper installation):

打包就像运行py2exe或pyInstaller一样简单。我的PyQt应用程序的内容在windows上是这样的(我在上面使用了InnoSetup来进行适当的安装):

pyticroque.exe           PyQt4.QtGui.pyd           unicodedata.pyd
MSVCP71.dll              PyQt4._qt.pyd             unins000.dat
MSVCR71.dll              python25.dll              unins000.exe
PyQt4.QtCore.pyd         sip.pyd                   _socket.pyd

QT comes with a widget designer and even in recent versions with an IDE to help design Qt software.

QT有一个小部件设计器,甚至在最近的版本中也有一个IDE来帮助设计QT软件。

PySide

PySide is a LGPL binding to Qt. It's developed by nokia as a replacement for the GPL PyQt.

PySide是一个与Qt绑定的LGPL,由诺基亚开发,作为GPL PyQt的替代品。

Although based on a different technology than the existing GPL-licensed PyQt bindings, PySide will initially aim to be API-compatible with them. In addition to the PyQt-compatible API, a more Pythonic API will be provided in the future.

尽管基于与现有gpl许可的PyQt绑定不同的技术,PySide最初的目标是与api兼容。除了兼容pyqt的API之外,将来还将提供一个更python化的API。

wxPython

wxPython is a binding for Python using the wxWidgets-Framework. This framework is under the LGPL licence and is developed by the open source community.

wxPython是使用wxwidgets框架的Python绑定。这个框架属于LGPL许可证,由开放源码社区开发。

What I'm really missing is a good tool to design the interface, they have about 3 but none of them is usable.

我真正缺少的是一个好的设计界面的工具,他们有3个,但是没有一个是可用的。

One thing I should mention is that I found a bug in the tab-view despite the fact that I didn't use anything advanced. (Only on Mac OS X) I think wxWidgets isn't as polished as Qt.

我应该提到的一件事是,我在选项卡视图中发现了一个bug,尽管我没有使用任何高级的东西。(仅在Mac OS X上)我认为wxWidgets没有Qt那么精美。

wxPython is really only about the GUI-classes, there isn't much else.

wxPython实际上只是关于gui类的,没有其他的。

wxWidgets uses native GUI elements.

wxWidgets使用本地GUI元素。

An advantage wxPython has over Tkinter is that wxPython has a much larger library of widgets from which to choose from.

与Tkinter相比,wxPython有一个优势,那就是wxPython有一个更大的小部件库,可以从中选择。

Others

I haven't got any experience with other GUI frameworks, maybe someone else has.

我没有使用其他GUI框架的经验,也许其他人有。

#2


6  

I'm just weighing in to say that TKinter sucks. It sadly seems that it is packed with Python because of backwards compatibility.

我只是想说,TKinter很烂。不幸的是,由于向后兼容性,它似乎被Python所包围。

The documentation is horrible. It looks horrible. I have run into some bizarre bugs that will actually crash Python.

文档是很可怕的。它看起来可怕。我遇到了一些奇怪的bug,它们实际上会导致Python崩溃。

#3


5  

I would definitely appreciate it if anyone knows of something better than what's commonly discussed; I see to have headaches finding something appropriate...

如果有人知道一些比通常讨论的更好的东西,我会非常感激;我看到头痛,找到合适的东西……

Qt is great, but PyQt doesn't seem to have the same development resources. It seems to have some clever way to generate bindings, but isn't complete (e.g. PyKDE terminal kpart) and there is a dearth of documentation (as the developers admit). Compatibility with Qt's UI designer is nice.

Qt很好,但是PyQt似乎没有相同的开发资源。它似乎有一些聪明的方法来生成绑定,但是不完整(例如PyKDE终端kpart),而且缺少文档(正如开发人员所承认的那样)。与Qt的UI设计器的兼容性很好。

wxpython - controls aren't as nice looking, widget library isn't as large as KDE.

wxpython -控件没有KDE那么好看,小部件库也没有KDE那么大。

OpenGL - doesn't even support fonts by default... pygame is okay, but opengl being a state machine is too annoying (object oriented models prevent making the a call in the wrong state).

OpenGL——默认情况下甚至不支持字体……pygame是可以的,但是opengl是一个状态机太烦人了(面向对象的模型可以防止调用错误的状态)。

XUL - neat idea, I wish it worked. The pyxulrunner tutorial didn't work for me, though -- first I had to add the xulrunner /usr/lib path to LD_LIBRARY_PATH, then it still had problems with "from xpcom import components"...

这个主意不错,我希望它能奏效。pyxulrunner教程并不适合我——首先我必须将xulrunner /usr/lib路径添加到LD_LIBRARY_PATH,然后它仍然有“来自xpcom导入组件”的问题……

my wishlist for a ui library would be

我对ui库的愿望列表是

  • Python integration (i.e. uses builtins like unicode, modules like threading, and language features like closures)
  • Python集成(例如使用unicode之类的内置程序、线程等模块和闭包之类的语言特性)
  • good intermediate representation (like XUL instead of generating hundreds of lines looking like "listbox91.addChild(label28)")
  • 良好的中间表示(比如XUL,而不是生成数百行,看起来像“listbox91.addChild(标签28)”)
  • simple mutlithreaded support (automatic locks or event posting so e.g. elt.setText can be called from any thread; let the designer manage locking with Python locks if necessary)
  • 简单的mutlithread支持(自动锁或事件发布,如elt)。可以从任何线程调用setText;如果需要,让设计器使用Python锁管理锁定)
  • user-centric features as well - scripting of a sequence of UI events, ability to keybind anything (KDE has dcop, but afaik binding isn't done automatically by the UI library), and intercept events.
  • 以用户为中心的特性——UI事件序列的脚本编写、键绑定任何东西的能力(KDE有dcop,但afaik绑定不是由UI库自动完成的),以及拦截事件。
  • potential for a large, easy-to-contribute standard library.
  • 潜在的大型、易于提供的标准库。
  • documentation, though if the library was well designed and generated enough interest, this would be a given.
  • 文档,尽管如果库设计得很好,并且产生了足够的兴趣,这将是给定的。

In my experience, html is so much easier to get something good-looking up than UI libraries.

在我的经验中,html比UI库更容易得到好看的东西。

edit - after working with PyQt 4 for a while, it gets the job done for simple UI's. I'm currently not developing for end users, so looks don't matter. The QTextBrowser is very useful for displaying basic HTML tables and generating HTML links.

编辑-与PyQt 4合作一段时间后,它将完成简单UI的工作。我目前没有为最终用户开发,所以外观并不重要。QTextBrowser对于显示基本的HTML表和生成HTML链接非常有用。

#4


5  

Jython.

Jython。

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

Jython是100%纯Java编写的高级、动态、面向对象语言Python的实现,并且与Java平台无缝集成。因此,它允许您在任何Java平台上运行Python。

You can use either Swing, Applet, or other GUI frameworks available to Java platform. See Java Tutorials for Graphical User Interfaces and 2D Graphics. There are plenty of books and documentation such as API reference.

您可以使用Swing、Applet或其他Java平台可用的GUI框架。有关图形用户界面和2D图形的Java教程。有大量的书籍和文档,如API参考。

Here's a Hello world Swing application from An Introduction to Jython.

下面是一个Hello world Swing应用程序,来自于Jython的介绍。

from javax.swing import *

frame = JFrame("Hello Jython")
label = JLabel("Hello Jython!", JLabel.CENTER)
frame.add(label)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(300, 300)
frame.show()

Here's a Jython applet by Todd Ditchendorf that demonstrates multi-threaded particle drawing (60 lines).

这是Todd Ditchendorf设计的Jython applet,它演示了多线程粒子绘图(60行)。

from __future__ import nested_scopes
import java.lang as lang
import java.util as util
import java.awt as awt
import javax.swing as swing

class Particle:

    def __init__(self,initX,initY):
    self.x = initX
    self.y = initY
    self.rng = util.Random()

    def move(self):
    self.x += self.rng.nextInt(10) - 5
    self.y += self.rng.nextInt(20) - 10

    def draw(self,g2):
    g2.drawRect(self.x,self.y,10,10)

class ParticleCanvas(awt.Canvas):

    def __init__(self,newSize):
    awt.Canvas.__init__(self,size=(newSize,newSize))

    def paint(self,g2):
    for p in self.particles:
        p.draw(g2)

class ParticleApplet(swing.JApplet):

    def init(self):
    self.canvas = ParticleCanvas(self.getWidth())
    self.contentPane.add(self.canvas)

    def start(self):
    n = 10
    particles = []
    for i in range(n):
        particles.append(Particle(150,150))
    self.canvas.particles = particles

    self.threads = []
    for i in range(n):
        self.threads.append(self.makeThread(particles[i]))
        self.threads[i].start()

    def makeThread(self,p):

    class MyRunnable(lang.Runnable):
        def run(this):
        try:
            while 1:
            p.move()
            self.canvas.repaint()
            lang.Thread.sleep(100)
        except lang.InterruptedException:
            return

    return lang.Thread(MyRunnable())

If you are just interested in drawing lines and circles you can probably cut it down to half.

如果你只对画线和圆感兴趣,你可以把它切成两半。

#5


0  

Pro wxPython

箴wxPython

  • Lots of tutorials
  • 很多教程
  • wxGlade as an Editor: not perfect yet, but usable.
  • wxGlade作为编辑:还不完美,但可用。

#1


43  

Please don't hesitate to expand this answer.

请毫不犹豫地扩展这个答案。

Tkinter

Tkinter is the toolkit that comes with python. That means you already have everything you need to write a GUI. What that also means is that if you choose to distribute your program, most likely everyone else already has what they need to run your program.

Tkinter是python自带的工具包。这意味着您已经拥有了编写GUI所需的一切。这也意味着,如果您选择发布您的程序,那么很可能其他人都已经拥有了运行您的程序所需的内容。

Tkinter is mature and stable, and is (at least arguably) quite easy to use.I found it easier to use than wxPython, but obviously that's somewhat subjective.

Tkinter是成熟和稳定的,并且(至少可以说)非常容易使用。我发现它比wxPython更容易使用,但显然这有点主观。

Tkinter gets a bad rap for looking ugly and out of date. While it's true that it's easy to create ugly GUIs with Tkinter, it's also pretty easy to create nice looking GUIs. Tkinter doesn't hold your hand, but it doesn't much get in the way, either. Tkinter looks best on the Mac and Windows since it uses native widgets there, but it looks OK on linux, too.

Tkinter因外表丑陋和过时而受到批评。虽然用Tkinter创建难看的gui很容易,但是创建漂亮的gui也很容易。Tkinter并没有握住你的手,但是它也不会阻碍你。Tkinter在Mac和Windows上看起来是最好的,因为它使用了本地的小部件,但是在linux上看起来也不错。

The other point about the look of Tkinter is that, for the most part, look isn't as important as people make it out to be. Most applications written with toolkits such as Tkinter, wxPython, PyQT, etc are special-purpose applications. For the types of applications these toolkits are used for, usability trumps looks. If the look of the application is important, it's easy enough to polish up a Tkinter application.

关于Tkinter外观的另一个观点是,在大多数情况下,外观并不像人们想象的那么重要。大多数使用工具包(如Tkinter、wxPython、PyQT等)编写的应用程序都是特殊用途的应用程序。对于这些工具包用于的应用程序类型,可用性优于外观。如果应用程序的外观很重要,那么就很容易改进Tkinter应用程序。

Tkinter has some features that other toolkits don't come close to matching. Variable traces, named fonts, geometry (layout) managers, and the way Tkinter processes events are still the standard to which other toolkits should be judged.

Tkinter有一些其他工具包无法匹配的特性。变量跟踪、命名字体、几何(布局)管理器和Tkinter处理事件的方式仍然是判断其他工具包的标准。

On the downside, Tkinter is a wrapper around a Tcl interpreter that runs inside python. This is mostly invisible to anyone developing with Tkinter, but it sometimes results in error messages that expose this architecture. You'll get an error complaining about a widget with a name like ".1245485.67345" which will make almost no sense to anyone unless you're also familiar with how Tcl/tk works.

缺点是,Tkinter是一个在python中运行的Tcl解释器的包装器。对于使用Tkinter开发的任何人来说,这几乎是不可见的,但它有时会导致暴露此架构的错误消息。您将会得到一个错误,抱怨一个名为“.1245485.67345”的小部件,这对任何人都没有意义,除非您还熟悉Tcl/tk的工作方式。

Another downside is that Tkinter doesn't have as many pre-built widgets as wxPython. The hierarchical tree widget in Tkinter is a little weak, for example, and there's no built-in table widget. On the other hand, Tkinter's canvas and text widgets are extremely powerful and easy to use. For most types of applications you will write, however, you'll have everything you need. Just don't expect to replicate Microsoft Word or Photoshop with Tkinter.

另一个缺点是Tkinter没有wxPython那么多预先构建的小部件。例如,Tkinter中的层次树小部件有点弱,而且没有内置的表小部件。另一方面,Tkinter的canvas和文本小部件非常强大,易于使用。然而,对于您将要编写的大多数类型的应用程序,您将拥有所需的一切。不要指望用Tkinter复制Microsoft Word或Photoshop。

I don't know what the license is for Tkinter, I assume the same as for python as a whole. Tcl/tk has a BSD-style license.

我不知道Tkinter的许可是什么,我假设python作为一个整体是一样的。Tcl/tk具有bsd样式的许可证。

PyQt

It's build on top of Qt, a C++ framework. It's quite advanced and has some good tools like the Qt Designer to design your applications. You should be aware though, that it doesn't feel like Python 100%, but close to it. The documentation is excellent

它构建在Qt之上,Qt是一个c++框架。它非常先进,并且有一些很好的工具,比如Qt设计器来设计应用程序。不过,您应该知道,它感觉不像100%的Python,但接近于它。文档是优秀的

This framework is really good. It's being actively developed by Trolltech, who is owned by Nokia. The bindings for Python are developed by Riverbank.

这个框架真的很好。诺基亚旗下的Trolltech公司正在积极开发这款手机。Python的绑定是由Riverbank开发的。

PyQt is available under the GPL license or a commercial one. The price of a riverbank PyQt license is about 400 euro per developer.

PyQt可以通过GPL许可或商业许可使用。河岸的PyQt许可证的价格大约是每个开发商400欧元。

Qt is not only a GUI-framework but has a lot of other classes too, one can create an application by just using Qt classes. (Like SQL, networking, scripting, …)

Qt不仅是一个gui框架,而且还有很多其他类,您可以通过使用Qt类来创建应用程序。(比如SQL、网络、脚本等等)

Qt used to emulate GUI elements on every platform but now uses native styles of the platforms (although not native GUI toolkits): see the documentation for Mac OS X and the windows XP style

Qt曾在每个平台上模拟GUI元素,但现在使用了平台的本地样式(尽管不是本地GUI工具包):请参阅Mac OS X和windows XP样式的文档

Packaging is as simple as running py2exe or pyInstaller. The content of my PyQt app looks like this on windows (I have used InnoSetup on top of it for proper installation):

打包就像运行py2exe或pyInstaller一样简单。我的PyQt应用程序的内容在windows上是这样的(我在上面使用了InnoSetup来进行适当的安装):

pyticroque.exe           PyQt4.QtGui.pyd           unicodedata.pyd
MSVCP71.dll              PyQt4._qt.pyd             unins000.dat
MSVCR71.dll              python25.dll              unins000.exe
PyQt4.QtCore.pyd         sip.pyd                   _socket.pyd

QT comes with a widget designer and even in recent versions with an IDE to help design Qt software.

QT有一个小部件设计器,甚至在最近的版本中也有一个IDE来帮助设计QT软件。

PySide

PySide is a LGPL binding to Qt. It's developed by nokia as a replacement for the GPL PyQt.

PySide是一个与Qt绑定的LGPL,由诺基亚开发,作为GPL PyQt的替代品。

Although based on a different technology than the existing GPL-licensed PyQt bindings, PySide will initially aim to be API-compatible with them. In addition to the PyQt-compatible API, a more Pythonic API will be provided in the future.

尽管基于与现有gpl许可的PyQt绑定不同的技术,PySide最初的目标是与api兼容。除了兼容pyqt的API之外,将来还将提供一个更python化的API。

wxPython

wxPython is a binding for Python using the wxWidgets-Framework. This framework is under the LGPL licence and is developed by the open source community.

wxPython是使用wxwidgets框架的Python绑定。这个框架属于LGPL许可证,由开放源码社区开发。

What I'm really missing is a good tool to design the interface, they have about 3 but none of them is usable.

我真正缺少的是一个好的设计界面的工具,他们有3个,但是没有一个是可用的。

One thing I should mention is that I found a bug in the tab-view despite the fact that I didn't use anything advanced. (Only on Mac OS X) I think wxWidgets isn't as polished as Qt.

我应该提到的一件事是,我在选项卡视图中发现了一个bug,尽管我没有使用任何高级的东西。(仅在Mac OS X上)我认为wxWidgets没有Qt那么精美。

wxPython is really only about the GUI-classes, there isn't much else.

wxPython实际上只是关于gui类的,没有其他的。

wxWidgets uses native GUI elements.

wxWidgets使用本地GUI元素。

An advantage wxPython has over Tkinter is that wxPython has a much larger library of widgets from which to choose from.

与Tkinter相比,wxPython有一个优势,那就是wxPython有一个更大的小部件库,可以从中选择。

Others

I haven't got any experience with other GUI frameworks, maybe someone else has.

我没有使用其他GUI框架的经验,也许其他人有。

#2


6  

I'm just weighing in to say that TKinter sucks. It sadly seems that it is packed with Python because of backwards compatibility.

我只是想说,TKinter很烂。不幸的是,由于向后兼容性,它似乎被Python所包围。

The documentation is horrible. It looks horrible. I have run into some bizarre bugs that will actually crash Python.

文档是很可怕的。它看起来可怕。我遇到了一些奇怪的bug,它们实际上会导致Python崩溃。

#3


5  

I would definitely appreciate it if anyone knows of something better than what's commonly discussed; I see to have headaches finding something appropriate...

如果有人知道一些比通常讨论的更好的东西,我会非常感激;我看到头痛,找到合适的东西……

Qt is great, but PyQt doesn't seem to have the same development resources. It seems to have some clever way to generate bindings, but isn't complete (e.g. PyKDE terminal kpart) and there is a dearth of documentation (as the developers admit). Compatibility with Qt's UI designer is nice.

Qt很好,但是PyQt似乎没有相同的开发资源。它似乎有一些聪明的方法来生成绑定,但是不完整(例如PyKDE终端kpart),而且缺少文档(正如开发人员所承认的那样)。与Qt的UI设计器的兼容性很好。

wxpython - controls aren't as nice looking, widget library isn't as large as KDE.

wxpython -控件没有KDE那么好看,小部件库也没有KDE那么大。

OpenGL - doesn't even support fonts by default... pygame is okay, but opengl being a state machine is too annoying (object oriented models prevent making the a call in the wrong state).

OpenGL——默认情况下甚至不支持字体……pygame是可以的,但是opengl是一个状态机太烦人了(面向对象的模型可以防止调用错误的状态)。

XUL - neat idea, I wish it worked. The pyxulrunner tutorial didn't work for me, though -- first I had to add the xulrunner /usr/lib path to LD_LIBRARY_PATH, then it still had problems with "from xpcom import components"...

这个主意不错,我希望它能奏效。pyxulrunner教程并不适合我——首先我必须将xulrunner /usr/lib路径添加到LD_LIBRARY_PATH,然后它仍然有“来自xpcom导入组件”的问题……

my wishlist for a ui library would be

我对ui库的愿望列表是

  • Python integration (i.e. uses builtins like unicode, modules like threading, and language features like closures)
  • Python集成(例如使用unicode之类的内置程序、线程等模块和闭包之类的语言特性)
  • good intermediate representation (like XUL instead of generating hundreds of lines looking like "listbox91.addChild(label28)")
  • 良好的中间表示(比如XUL,而不是生成数百行,看起来像“listbox91.addChild(标签28)”)
  • simple mutlithreaded support (automatic locks or event posting so e.g. elt.setText can be called from any thread; let the designer manage locking with Python locks if necessary)
  • 简单的mutlithread支持(自动锁或事件发布,如elt)。可以从任何线程调用setText;如果需要,让设计器使用Python锁管理锁定)
  • user-centric features as well - scripting of a sequence of UI events, ability to keybind anything (KDE has dcop, but afaik binding isn't done automatically by the UI library), and intercept events.
  • 以用户为中心的特性——UI事件序列的脚本编写、键绑定任何东西的能力(KDE有dcop,但afaik绑定不是由UI库自动完成的),以及拦截事件。
  • potential for a large, easy-to-contribute standard library.
  • 潜在的大型、易于提供的标准库。
  • documentation, though if the library was well designed and generated enough interest, this would be a given.
  • 文档,尽管如果库设计得很好,并且产生了足够的兴趣,这将是给定的。

In my experience, html is so much easier to get something good-looking up than UI libraries.

在我的经验中,html比UI库更容易得到好看的东西。

edit - after working with PyQt 4 for a while, it gets the job done for simple UI's. I'm currently not developing for end users, so looks don't matter. The QTextBrowser is very useful for displaying basic HTML tables and generating HTML links.

编辑-与PyQt 4合作一段时间后,它将完成简单UI的工作。我目前没有为最终用户开发,所以外观并不重要。QTextBrowser对于显示基本的HTML表和生成HTML链接非常有用。

#4


5  

Jython.

Jython。

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

Jython是100%纯Java编写的高级、动态、面向对象语言Python的实现,并且与Java平台无缝集成。因此,它允许您在任何Java平台上运行Python。

You can use either Swing, Applet, or other GUI frameworks available to Java platform. See Java Tutorials for Graphical User Interfaces and 2D Graphics. There are plenty of books and documentation such as API reference.

您可以使用Swing、Applet或其他Java平台可用的GUI框架。有关图形用户界面和2D图形的Java教程。有大量的书籍和文档,如API参考。

Here's a Hello world Swing application from An Introduction to Jython.

下面是一个Hello world Swing应用程序,来自于Jython的介绍。

from javax.swing import *

frame = JFrame("Hello Jython")
label = JLabel("Hello Jython!", JLabel.CENTER)
frame.add(label)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(300, 300)
frame.show()

Here's a Jython applet by Todd Ditchendorf that demonstrates multi-threaded particle drawing (60 lines).

这是Todd Ditchendorf设计的Jython applet,它演示了多线程粒子绘图(60行)。

from __future__ import nested_scopes
import java.lang as lang
import java.util as util
import java.awt as awt
import javax.swing as swing

class Particle:

    def __init__(self,initX,initY):
    self.x = initX
    self.y = initY
    self.rng = util.Random()

    def move(self):
    self.x += self.rng.nextInt(10) - 5
    self.y += self.rng.nextInt(20) - 10

    def draw(self,g2):
    g2.drawRect(self.x,self.y,10,10)

class ParticleCanvas(awt.Canvas):

    def __init__(self,newSize):
    awt.Canvas.__init__(self,size=(newSize,newSize))

    def paint(self,g2):
    for p in self.particles:
        p.draw(g2)

class ParticleApplet(swing.JApplet):

    def init(self):
    self.canvas = ParticleCanvas(self.getWidth())
    self.contentPane.add(self.canvas)

    def start(self):
    n = 10
    particles = []
    for i in range(n):
        particles.append(Particle(150,150))
    self.canvas.particles = particles

    self.threads = []
    for i in range(n):
        self.threads.append(self.makeThread(particles[i]))
        self.threads[i].start()

    def makeThread(self,p):

    class MyRunnable(lang.Runnable):
        def run(this):
        try:
            while 1:
            p.move()
            self.canvas.repaint()
            lang.Thread.sleep(100)
        except lang.InterruptedException:
            return

    return lang.Thread(MyRunnable())

If you are just interested in drawing lines and circles you can probably cut it down to half.

如果你只对画线和圆感兴趣,你可以把它切成两半。

#5


0  

Pro wxPython

箴wxPython

  • Lots of tutorials
  • 很多教程
  • wxGlade as an Editor: not perfect yet, but usable.
  • wxGlade作为编辑:还不完美,但可用。