Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Python Programming/GUI Programming

From Wikibooks, open books for an open world
<Python Programming
Previous: SocketsIndexNext: CGI interface


There are various GUI toolkits usable from Python.

Very productive are true GUI-builders, where the programmer can arrange the GUI window and other components such as database by using the mouse only in an intuitive fashion like in Windows Delphi 2.0. Very little typing is required. For python, only Boa Constructor follows this paradigm. WXglade and Qt-designer, monkey studio etc. come somewhat near but remain incomplete.

Disadvantages with the following kits described below are:

  • Difficult deployment - the apps won't run on a particular GNU-Linux installation without major additional work
  • breakage - apps won't work due to bit-rot.

Tkinter

[edit |edit source]

Tkinter is a Python wrapper for Tcl/Tk providing a cross-platform GUI toolkit. On Windows, it comes bundled with Python; on other operating systems, it can be installed. The set of available widgets is smaller than in some other toolkits, but since Tkinter widgets are extensible, many of the missing compound widgets can be created using the extensibility, such as combo box and scrolling pane.

A minimal example:

fromTkinterimport*root=Tk()frame=Frame(root)frame.pack()label=Label(frame,text="Hey there.")label.pack()quitButton=Button(frame,text="Quit",command=frame.quit)quitButton.pack()root.mainloop()

Main chapter:Tkinter.

Links:

PyGTK

[edit |edit source]

See also bookPyGTK For GUI Programming

PyGTK provides a convenient wrapper for theGTK+ library for use in Python programs, taking care of many of the boring details such as managing memory and type casting. The bare GTK+ toolkit runs on Linux, Windows, and Mac OS X (port in progress), but the more extensive features — when combined with PyORBit and gnome-python — require aGNOME install, and can be used to write full featured GNOME applications.

Home Page

PyQt

[edit |edit source]

PyQt is a wrapper around the cross-platformQt C++ toolkit. It has manywidgets and support classes supporting SQL, OpenGL, SVG, XML, and advanced graphics capabilities.A PyQt hello world example:

fromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*classApp(QApplication):def__init__(self,argv):super(App,self).__init__(argv)self.msg=QLabel("Hello, World!")self.msg.show()if__name__=="__main__":importsysapp=App(sys.argv)sys.exit(app.exec_())

PyQt is a set of bindings for the cross-platformQt application framework. PyQt v4 supports Qt4 and PyQt v3 supports Qt3 and earlier.

wxPython

[edit |edit source]

Bindings for the cross platform toolkitwxWidgets. WxWidgets is available on Windows, Macintosh, and Unix/Linux.

importwxclasstest(wx.App):def__init__(self):wx.App.__init__(self,redirect=False)defOnInit(self):frame=wx.Frame(None,-1,"Test",pos=(50,50),size=(100,40),style=wx.DEFAULT_FRAME_STYLE)button=wx.Button(frame,-1,"Hello World!",(20,20))self.frame=frameself.frame.Show()returnTrueif__name__=='__main__':app=test()app.MainLoop()

Dabo

[edit |edit source]

Dabo is a full 3-tier application framework. Its UI layer wraps wxPython, and greatly simplifies the syntax.

importdabodabo.ui.loadUI("wx")classTestForm(dabo.ui.dForm):defafterInit(self):self.Caption="Test"self.Position=(50,50)self.Size=(100,40)self.btn=dabo.ui.dButton(self,Caption="Hello World",OnHit=self.onButtonClick)self.Sizer.append(self.btn,halign="center",border=20)defonButtonClick(self,evt):dabo.ui.info("Hello World!")if__name__=='__main__':app=dabo.ui.dApp()app.MainFormClass=TestFormapp.start()


pyFltk

[edit |edit source]

pyFltk is a Python wrapper for theFLTK, a lightweight cross-platform GUI toolkit. It is very simple to learn and allows for compact user interfaces.

The "Hello World" example in pyFltk looks like:

fromfltkimport*window=Fl_Window(100,100,200,90)button=Fl_Button(9,20,180,50)button.label("Hello World")window.end()window.show()Fl.run()

Other Toolkits

[edit |edit source]
  • PyKDE - Part of the kdebindings package, it provides a python wrapper for the KDE libraries.
  • PyXPCOM provides a wrapper around the MozillaXPCOM component architecture, thereby enabling the use of standaloneXUL applications in Python. The XUL toolkit has traditionally been wrapped up in various other parts of XPCOM, but with the advent oflibxul and XULRunner this should become more feasible. These days, nobody uses PyXPCOM for very good reasons: PyXPCOM gives one dead links and outdated incompatible firefox extensions.

External links

[edit |edit source]
Previous: SocketsIndexNext: CGI interface
Retrieved from "https://en.wikibooks.org/w/index.php?title=Python_Programming/GUI_Programming&oldid=3676211"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp