开发者

are there any cross platform window toolkits for python that aren't made by crazy people?

well maybe crazy is a bit too strong of a word, but what I am asking is if there are any window toolkits out there that don't have me do this:

class MyApp(SomeWindowClass):

I really don't want to use a library made by someone who is so obsessed with objects that he/she thinks that there should be a class for the app (which there will only be one instance of, so I don开发者_StackOverflow社区't see why anyone would want to do that extra typing) (btw, no offense intended towards anyone who agrees with the way these libraries are set up, I just really want to know if there is anything out there with a tad bit less objects)


In general GUI toolkits rely on having some form of event loop running, the Application class in these toolkits is generally in charge of that event loop and marshaling events from the underlying window manager. Sure they could call the class EventLoopManager or something, but you need it either way so its just a naming thing then. In some cases though some toolkits who often use events can occasionally be used without them, and then you certainly dont want it to be some automatic thing.


There is PyQT.


Tkinter has one object per window/dialog, not app, and requires no classes to get something painted on the screen. It does, however, have its own main loop (like all the other GUI libraries). Obligatory Hello World:

from Tkinter import *
root = Tk()    
w = Label(root, text="Hello, world!")
w.pack()    
root.mainloop()


PyGTK another toolkit; which is python binding of Gtk. It is well structured with having excellent window and event loop system. A typical example to show a window

import gtk
class Application:
    def __init__(self):
        self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
        self.window.show()

if __name__ == "__main__":
    app = Application()
    gtk.mainloop()

Another recommendation is PyQt; which is python binding of Qt. Typical hello world example is

    import sys
    from qt import *

    app = QApplication(sys.argv)
    myLabel = QLabel("Hello world!", None)
    app.setMainWidget(myLabel)
    myLabel.show()

    app.exec_loop()

PyQt and PyGtk are widely used for rapid GUI development. From my experience pyGtk is poor in the online documentation/support compared to pyQt. But both are favorite of mine.


As you see with the answers above, GUI programming is almost always heavily object oriented, and there are good reasons for this: the graphical elements share a lot in terms of how they can be positioned within one-another, caring about whether the mouse pointer is over them etc. Furthermore, the C++ kits that qt, wx, gtk et al. wrap are already structured on a class/inheritance hierarchy, so you should not be surprised that the python wrappers are also.

If you want only simple GUI elements, then you may consider easyGUI (simple message boxes, text edit, choices), triatsUI (interactive object wrappers, primarily for controlling graphical objects) , which each solve some part of the GUI interactions without explicitly having you write GUI code. For editing the values of fields in a record-like structure, you could also investigate GUIdata.

PS: there are various graphical tools out there to let you design your GUIs and link together some of the events, e.g., QtDesigner, that can help you avoid much of the tedious class definition code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜