Python Programming/GUI Programming

< Python Programming


Tkinter, a Python wrapper for Tcl/Tk, comes bundled with Python (at least on Win32 platform though it can be installed on Unix/Linux and Mac machines) and provides a cross-platform GUI. It is a relatively simple to learn yet powerful toolkit that provides what appears to be a modest set of widgets. However, because the Tkinter widgets are extensible, many compound widgets can be created rather easily (e.g. combo-box, scrolled panes). Because of its maturity and extensive documentation Tkinter has been designated as the de facto GUI for Python.

To create a very simple Tkinter window frame one only needs the following lines of code:

import Tkinter

root = Tkinter.Tk()

From an object-oriented perspective one can do the following:

import Tkinter

class App:
    def __init__(self, master):
        button = Tkinter.Button(master, text="I'm a Button.")

if __name__ == '__main__':
    root = Tkinter.Tk()
    app = App(root)

To learn more about Tkinter visit the following links:


See also book PyGTK For GUI Programming

PyGTK provides a convenient wrapper for the GTK+ 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 a GNOME install, and can be used to write full featured GNOME applications.

Home Page


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

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class App(QApplication):
    def __init__(self, argv):
        super(App, self).__init__(argv)
        self.msg = QLabel("Hello, World!")

if __name__ == "__main__":
    import sys
    app = App(sys.argv)

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


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

import wx

class test(wx.App):
    def __init__(self):
        wx.App.__init__(self, redirect=False)

    def OnInit(self):
        frame = wx.Frame(None, -1,
                         pos=(50,50), size=(100,40),
        button = wx.Button(frame, -1, "Hello World!", (20, 20))
        self.frame = frame
        return True

if __name__ == '__main__':
        app = test()


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

import dabo

class TestForm(dabo.ui.dForm):
	def afterInit(self):
		self.Caption = "Test"
		self.Position = (50, 50)
		self.Size = (100, 40)
		self.btn = dabo.ui.dButton(self, Caption="Hello World",
		self.Sizer.append(self.btn, halign="center", border=20)
	def onButtonClick(self, evt):"Hello World!")

if __name__ == '__main__':
        app = dabo.ui.dApp()
        app.MainFormClass = TestForm


pyFltk is a Python wrapper for the FLTK, 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:

from fltk import *

window = Fl_Window(100, 100, 200, 90)
button = Fl_Button(9,20,180,50)
button.label("Hello World")

Other ToolkitsEdit

  • PyKDE - Part of the kdebindings package, it provides a python wrapper for the KDE libraries.
  • PyXPCOM provides a wrapper around the Mozilla XPCOM component architecture, thereby enabling the use of standalone XUL applications in Python. The XUL toolkit has traditionally been wrapped up in various other parts of XPCOM, but with the advent of libxul and XULRunner this should become more feasible.
Read in another language