Wikibooksβ

Programming with Gtk2-Perl/Introduction

Contents

The book is targeted to people with at least some experience programming with Perl. General programming topics and semantics of the Perl programming language will not be discussed. The focus will be on using the Gtk2-Perl API to create graphical applications. If you are new to programming or to Perl - you should do some soul searching before continuing on.

Gtk is a library for creating graphical user interfaces. Gtk stands for the GIMP toolkit - named because it was developed for the GNU Image Manipulation Program. Gtk is free open-source software. It is licensed under the LGPL, which means you can develop free/open software or commercial software with it without paying licensing fees.

The Gtk+ libraries are written in the C programming language, but can be used from a multitude of other languages such as Perl, Python, Ruby, PHP, Java and others. A complete list of supported language bindings can be found at http://www.gtk.org/language-bindings.php.

The GIMP drawing kit and gdk-pixbuf are low level functions for window handling and image manipulation. The two Perl modules for these libraries can be found within the Gtk2 namespace as Gtk2::Gdk and Gtk2::Gdk::Pixbuf.

Glib replaces some native *nix call with it's own versions, to either add functionality or the increase portability of Gtk. Glib also provides the underlying type system behind Gtk's class hierarchy, the signal system used in Gtk, a thread API as well a facility for loading of modules. The Glib library is bound under the Glib namespace.

Perl is most likely installed on your computer. If it's not - get it here.

Gtk+ is also probably installed on your system. If not, you should look for pre-built binaries on the internet specifically for your operating system. A simple Google search will most likely yield the results you are looking for. If there are no binaries available for your operating system, you can compile Gtk+ on your own.

Once you have Gtk+ and Perl on your system, you need to install the Perl language bindings. Like most great things perl, you can install the gtk-perl libraries via CPAN. Enter the following command at a prompt to automatically install.

perl -MCPAN -e 'install Gtk2'

If you have issues installing from the CPAN utility, you can download the module and install it manually. After downloading and extracting the archive, issues these commands from the root of the extracted folder.

Getting Gtk2 and Gtk2-Perl running on windows has its caveats, due to the fact that windows doesn't ship with all the necessary utilities to compile it(and lots of other great open-source software). Here are your three options.

And the recommended way. Download and install camelbox. Bam - you're done. The drawback is that things that are readily available from ActiveState's ppm repository like libexpat and libgd are not readily available with camelbox. It may be more difficult to compile these libraries, should you need them, than that it is to compile your own Gtk+ from source. In general, camelbox should be sufficient for most users and has the options and tools to install a lot of useful modules and utilities.

Follow the instructions at http://lostmind.de/gtk2-perl/. This website details everything you need to get Gtk2-perl working using ActiveState Perl 5.8.8 build 819. The drawback: it is all dated. It is an old version of Perl and more importantly and old version of Gtk+. There are a lot of features that have been implemented in both Gtk+ and the Perl language bindings that just did not exist at the time.