| PyGTK Tutorial | ||
|---|---|---|
| <<< Previous | Next >>> | |
James Henstridge james@daa.com.au
Python is an extensible, object-oriented interpreted programming
language which is provided with a rich set of modules providing access to
a large number of operating system services, internet services (such as HTML,
XML, FTP, etc.), graphics (including OpenGL, TK, etc.), string handling functions,
mail services (IMAP, SMTP, POP3, etc.), multimedia (audio, JPEG) and cryptographic
services. In addition there are many other modules available from third
parties providing many other services. Python is licensed under terms similar
to the LGPL license and is available for Linux, Unix , Windows and Macintosh
operating systems. More information on Python is available at www.python.org. The primary Author of Python
is:
Guido van Rossum guido@python.org
GTK (GIMP Toolkit) is a library for creating graphical user interfaces.
It is licensed using the LGPL license, so you can develop open software,
free software, or even commercial non-free software using GTK without having
to spend anything for licenses or royalties.
It's called the GIMP toolkit because it was originally written for developing the GNU Image Manipulation Program (GIMP), but GTK has now been used in a large number of software projects, including the GNU Network Object Model Environment (GNOME) project. GTK is built on top of GDK (GIMP Drawing Kit) which is basically a wrapper around the low-level functions for accessing the underlying windowing functions (Xlib in the case of the X windows system). The primary authors of GTK are:
Spencer Kimball spencer@xcf.berkeley.edu
Josh MacDonald jmacd@xcf.berkeley.edu
There is also a third component called GLib which contains a few replacements for some standard calls, as well as some additional functions for handling linked lists, etc. The replacement functions are used to increase GTK's portability, as some of the functions implemented here are not available or are nonstandard on other unixes such as g_strerror(). Some also contain enhancements to the libc versions, such as g_malloc that has enhanced debugging utilities.
This tutorial describes the Python interface to GTK+ and is based on the GTK+ Tutorial written by Tony Gale and Ian Main. PyGTK provides two interfaces to Python: a high level object-oriented interface and a lower level functional interface; this tutorial describes only the high level object-oriented interface. This tutorial attempts to document as much as possible of PyGTK, but is by no means complete.
This tutorial assumes some understanding of Python, and how to create and run Python programs. If you are not familiar with Python, please read the Python Tutorial first. This tutorial does not assume an understanding of GTK; if you are learning PyGTK to learn GTK, please comment on how you found this tutorial, and what you had trouble with. This tutorial does not describe how to compile or install Python, GTK+ or PyGTK.
This tutorial is based on:
GTK+ 1.2.9The examples were written and tested on a RedHat 7.1 system.
Python 1.5.2
PyGTK 0.6.6 (part of PyGNOME 1.0.53)
This document is a "work in progress". Please look for updates on www.moeraki.com.
I would very much like to hear of any problems you have learning PyGTK from this document, and would appreciate input as to how it may be improved. Please see the section on Contributing for further information.
Johan Dahlin has written a small Python program (pygtkconsole.py) that runs on Linux and allows interactive exploration of PyGTK. The program provides a Python-like interactive interpreter interface that communicates with a child process that executes that entered commands. The PyGTK modules are loaded by default. A simple example session is:
moe: 96:1095$ pygtkconsole.py |
This creates a window containing a button (labeled 'Hello') which prints a message ('Hello, World!') when clicked. The label on the button is then chnaged to 'Hi There'.
This program makes it easy to try out various GTK widgets and PyGTK interfaces.
| <<< Previous | Home | Next >>> |
| PyGTK Tutorial | Getting Started |