GTK-Perl is the collective name for a set of perl bindings for GLib, GTK+, 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.
GTK-Perl Resources
Official web site: http://gtk2-perl.sourceforge.net
GTK-Perl Documentation
GTK-Perl Modules
GNOME Platform Bindings Modules
Name
Description
Glib
GLib and GObject 2.0 bindings
Glib::Object::Introspection
GObjectIntrospection bindings
Cairo
Cairo bindings
Pango
Pango bindings
Gtk3
GTK+ 3.x bindings
Gtk2
GTK+ 2.x bindings
The GTK+ 2.x bindings are static and use Perl's XS language.
The GTK+ 3.x bindings are dynamically generated through Glib::Object::Introspection.
The following bindings belong to the GNOME 2.x platform, and are considered deprecated. They should not be used in newly written code.
Name
Description
Replaced by
Gtk2::GladeXML
UI building library
GtkBuilder in GTK+
Gnome2
Gnome and Gnome UI bindings
Various classes in GTK+
Gnome2::Canvas
A structured graphics canvas
-
Gnome2::VFS
Gnome VFS bindings
Various classes in GIO
Gnome2::GConf
GConf bindings
GSettings in GIO
Other Modules
Name
Description
Notes
Gnome2::Print
Gnome Print infrastructure
Replaced by the printing API in GTK+
Gnome2::VTE
Terminal emulator widget
Gnome2::RSVG
SVG parser and display library
Gnome2::Dia
Diagrams
Gnome2::Wnck
Window navigator construction kit
GStreamer
Audio/Video infrastructure using GStreamer 0.x
Replaced by GStreamer1
GStreamer::GConf
GConf interaction facilities for GStreamer 0.x
GConf is deprecated
Gtk2::GLExt
3D modelling using OpenGL
Replaced by OpenGL support in GTK+
Gtk2::HTML2
HTML viewer widget
Replaced by WebKitGtk
Gtk2::MozEmbed
HTML viewer widget using the Gecko rendering engine
Replaced by WebKitGtk
Gtk2::SourceView
Powerful editor widget
Gtk2::Spell
Spellcheck widget
Gtk2::TrayIcon
Notification area icon
Replaced by GtkStatusIcon in GTK+
GTK-Perl Development
The modules that make up GTK-Perl are hosted on GNOME git. To get the repository name from the module's main package, prepend 'perl-' and replace '::' with '-'. For example, Glib lives in the perl-Glib repository and Gnome2::Canvas in perl-Gnome2-Canvas.
To check out a module, use:
git clone git://git.gnome.org/<module>
GTK-Perl "Hello, World!" Program
use strict; use warnings; use v5.18; use Glib ':constants'; # load Glib and import useful constants use Gtk3 '-init'; # load Gtk3 module and initialize it my $window = Gtk3::Window->new('toplevel'); # create a new window # Here we connect the "destroy" event to a signal handler. # This event occurs when we call Gtk3::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 { Gtk3::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 = Gtk3::Button->new("Hello World"); $button->signal_connect(clicked => sub { my ($button) = @_; say "Hello, World!"; # 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). Gtk3::main(); # Once the main_quit() method stops the main loop, control is returned to this # point. In this case, we simply exit successfully. 0;