PyGTK
Set of Python wrappers for the GTK graphical user interface library
- 2 min read
- 2 chapters
Related on Lably
Through Python (programming language), Graphical user interface and Library (computing)
PyGTK was phased out with the transition to GTK version 3 and be replaced with PyGObject, which uses GObject Introspection to generate bindings for Python and other languages on the fly. This is expected to eliminate the delay between GTK updates and corresponding language binding updates, as well as reduce maintenance burden on the developers.
Syntax
The Python code below will produce a 200x200 pixel window with the words "Hello World" inside.
<span id="mwNw"></span><span class="kn" id="mwOA">import</span><span class="w" id="mwOQ"> </span><span class="nn" id="mwOg">gtk</span> <span class="k" id="mwOw">def</span><span class="w" id="mwPA"> </span><span class="nf" id="mwPQ">create_window</span><span class="p" id="mwPg">():</span> <span class="n" id="mwPw">window</span> <span class="o" id="mwQA">=</span> <span class="n" id="mwQQ">gtk</span><span class="o" id="mwQg">.</span><span class="n" id="mwQw">Window</span><span class="p" id="mwRA">()</span> <span class="n" id="mwRQ">window</span><span class="o" id="mwRg">.</span><span class="n" id="mwRw">set_default_size</span><span class="p" id="mwSA">(</span><span class="mi" id="mwSQ">200</span><span class="p" id="mwSg">,</span> <span class="mi" id="mwSw">200</span><span class="p" id="mwTA">)</span> <span class="n" id="mwTQ">window</span><span class="o" id="mwTg">.</span><span class="n" id="mwTw">connect</span><span class="p" id="mwUA">(</span><span class="s2" id="mwUQ">"destroy"</span><span class="p" id="mwUg">,</span> <span class="n" id="mwUw">gtk</span><span class="o" id="mwVA">.</span><span class="n" id="mwVQ">main_quit</span><span class="p" id="mwVg">)</span> <span class="n" id="mwVw">label</span> <span class="o" id="mwWA">=</span> <span class="n" id="mwWQ">gtk</span><span class="o" id="mwWg">.</span><span class="n" id="mwWw">Label</span><span class="p" id="mwXA">(</span><span class="s2" id="mwXQ">"Hello World"</span><span class="p" id="mwXg">)</span> <span class="n" id="mwXw">window</span><span class="o" id="mwYA">.</span><span class="n" id="mwYQ">add</span><span class="p" id="mwYg">(</span><span class="n" id="mwYw">label</span><span class="p" id="mwZA">)</span> <span class="n" id="mwZQ">label</span><span class="o" id="mwZg">.</span><span class="n" id="mwZw">show</span><span class="p" id="mwaA">()</span> <span class="n" id="mwaQ">window</span><span class="o" id="mwag">.</span><span class="n" id="mwaw">show</span><span class="p" id="mwbA">()</span> <span class="n" id="mwbQ">create_window</span><span class="p" id="mwbg">()</span> <span class="n" id="mwbw">gtk</span><span class="o" id="mwcA">.</span><span class="n" id="mwcQ">main</span><span class="p" id="mwcg">()</span>
Notable applications that have used PyGTK
PyGTK has been used in a number of notable applications, some examples:
- Anaconda installer
- BitTorrent
- Deluge
- Exaile
- Gajim
- Gedit (for optional Python subsystem and plugins)
- GIMP (for optional Python scripts)
- GNOME Sudoku
- Gramps
- Jokosher
- puddletag
- Pybliographer
- Tryton
- ROX Desktop (includes ROX-Filer)
- SoundConverter
- Ubiquity (Ubuntu installer)
- Ubuntu Software Center
- Wing IDE
Sign in to keep reading
One more chapter is free with a Lably account.
PyGObject
PyGObject provides a wrapper for use in Python programs when accessing GObject libraries. GObject is an object system used by GTK, GLib, GIO, GStreamer and other libraries.
Like the GObject library itself, PyGObject is licensed under the GNU LGPL, so it is suitable for use in both free software and proprietary applications. It is already in use in many applications ranging from small single-purpose scripts to large full-featured applications.
PyGObject can dynamically access any GObject libraries that use GObject Introspection. It replaces the need for separate modules such as PyGTK, GIO and python-gnome to build a full GNOME 3.0 application. Once new functionality is added to GObject library it is instantly available as a Python API without the need for intermediate Python glue.
Notable applications that use PyGObject
PyGObject has replaced PyGTK, but it has taken a considerable amount of time for many programs to be ported. Most of the software listed here has an older version which used PyGTK.
- Gramps
- Meld
- Pitivi
- PyChess
- Quod Libet

