This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

/!\ Attention: PyGTK only supports the Gtk-2.X API (NOT Gtk-3.0 or later versions) and the information on this page may be outdated. Do not use PyGTK for new projects. Please port existing applications from PyGTK to PyGObject. For more information see the the PyGObject documentation.

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. When combined with PyORBit and gnome-python, it can be used to write full featured GNOME applications (see the Python page). Official website of PyGTK is http://www.pygtk.org

GTK+ is a GUI toolkit for developing graphical applications that run on POSIX systems such as Linux, Windows and MacOS X (provided that an X server for MacOS X has been installed). It provides a comprehensive set of widgets, and supports Unicode and bidirectional text. It links into the Gnome Accessibility Framework through the ATK library.

Python is an interpreted, interactive, object-oriented programming language. It is often compared to Tcl, Perl, Scheme or Java. Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing.

PyGTK Documentation

FAQ

PyGTK Tutorial

PyGTK Reference

Articles & Tutorials

PyGTK Development

Developer Resources for PyGObject

PyGTK Git repository (archived and unmaintained)

Code repository access

Information on accessing and using GNOME's Git server is available in the Gnome Wiki.

Modules in Gnome Git:

PyGTK "Hello, World!" Program

   1 #!/usr/bin/env python
   2 import pygtk
   3 pygtk.require('2.0')
   4 import gtk
   5 # Create a new window
   6 window = gtk.Window()
   7 
   8 # Here we connect the "delete-event" event to a signal handler.
   9 # This event occurs when we the user closes window,
  10 # We connect it to gtk.main_quit, so it quits the main loop
  11 # and the program terminates
  12 window.connect("delete-event", gtk.main_quit)
  13 
  14 # Sets the border width of the window.
  15 window.set_border_width(10)
  16 
  17 # Creates a new button with the label "Hello World".
  18 button = gtk.Button("Hello World")
  19 
  20 # This is a callback function, which we later will connect
  21 # to the clicked signal of the button, which will be triggered
  22 # when the user clicks the button with a mouse.
  23 def on_button_clicked(button):
  24     print "Hello World"
  25 # When the button receives the "clicked" signal, it will call the
  26 # function hello() defined above.
  27 button.connect("clicked", on_button_clicked)
  28 
  29 # This packs the button into the window (which is a container).
  30 window.add(button)
  31 
  32 # Show the window and the button
  33 window.show_all()
  34 # Run the main loop, to process events such a key presses
  35 # and mouse movements.
  36 gtk.main()

And the output of the above program will look like this:

hello.jpg

Support and Feedback

Mailing List

There is a main mailing list for PyGTK. To subscribe to the list, use the web interface at

The mailing address of the list is pygtk@daa.com.au . The mailing list is archived at mail-archive.com and at daa.com.au.

IRC Channel

There is an IRC Channel called #pygtk in the irc.gnome.org (aka irc.gimp.net) network. People there are eager to help; go and meet some other PyGTK hackers!

PyGTK Downloads

PyGTK is included in most GNU/Linux distributions (including Connectiva, Debian, Fedora, Mandrake, Redhat, SUSE and Ubuntu); the source code can also be downloaded and compiled from the links below.

Current stable version (GTK+ 2.24.0)

Note: PyGTK 2.24 will be the last major release in the PyGTK series.

GNOME dependencies

If you want to make use of the Gnome libraries in your application, you may wish to install the gnome-python and gnome-python-desktop packages. In addition to this, gnome-python-extras is also available (contains less frequently used packages not in gnome-python). All are available from the Gnome FTP site and its mirrors:

For more, see the Python page.

Windows (Win32) Port

The Win32 port of PyGTK is maintained by John Stowers and Dieter Verfaillie.

You can get Win32 binaries and an all-in-one installer on the gnome ftp site: PyGTK for Win32 binaries. Note that the FAQ also includes a number of items on PyGTK and Win32. Instructions on building PyGTK on windows can be found here.


2024-10-23 11:37