GTK2-Perl is the collective name for a set of perl bindings for GTK+ 2.x and various related libraries. These modules make it easy to write Gtk and Gnome applications using a natural, perlish, object-oriented syntax.

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.

Perl is a stable, multi-platform programming language, used throughout the entire Internet and in many mission-critical environments.

GTK2-Perl is part of the official GNOME Platform Bindings

GTK2-Perl Resources

GTK2-Perl Documentation

GTK2-Perl Modules

Gnome Platform Bindings Modules

These modules are actively maintained, and follow the Gnome Release Schedule.

Other Modules

These modules reside in the GTK2-Perl CVS server, and do not follow a strict release schedule.

GTK2-Perl Development

You can browse the GTK2-Perl CVS here.

To check out GTK2-Perl CVS:

export CVSROOT=":pserver:anonymous@cvs.sourceforge.net:/cvsroot/gtk2-perl"
cvs login # Just press Enter when asked for a password
cvs -z3 co gtk2-perl-xs

GTK2-Perl "Hello, World!" Program

use strict;
use warnings;

use Glib qw/TRUE FALSE/; # import TRUE and FALSE constants for readability
use Gtk2 '-init';        # load Gtk2 module, and initialize it

my $window = Gtk2::Window->new('toplevel'); # create a new window

# Here we connect the "destroy" event to a signal handler.
# This event occurs when we call Gtk2::Widget::destroy on the window.
# Perl supports anonymous subs, so we can use one of them for one line
# callbacks.
$window->signal_connect(destroy => sub { Gtk2->main_quit; });

# Sets the border width of the window.
$window->set_border_width(10);

# Creates a new button with a label "Hello World".
my $button = Gtk2::Button->new("Hello World");

$button->signal_connect(clicked => sub {
        my ($button) = @_;

        print "Hello, World!\n";
        
        # We can use variables defined outside the sub's scope, thanks
        # to Perl closures.
        $window->destroy;
    });

# This packs the button into the window (a gtk container).
$window->add($button);

# The final step is to display this newly created widget.
$button->show;

# and the window
$window->show;

# All GTK applications must have a call to the main() method. Control ends here
# and waits for an event to occur (like a key press or a mouse event).
Gtk2->main;

0;

GTK2-Perl (last edited 2008-02-03 14:44:17 by localhost)