How to setup Gtk2 for perl in Ubuntu 9.04

You will need the following packages

sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev libglib2.0-dev libpango1.0-dev

Now run cpan

sudo cpan

Install the following in order

install ExtUtils::Depends
install ExtUtils::PkgConfig
install Glib
instal Pango
install Gtk2

And now you done, you can test it with the following script:

#!/usr/bin/perl
use Gtk2 -init;

my $window = Gtk2::Window->new ('toplevel');
my $button = Gtk2::Button->new ('Quit');
$button->signal_connect (clicked => sub { Gtk2->main_quit });
$window->add ($button);
$window->show_all;
Gtk2->main;

To run it save the script as gtk-test.pl and run

perl gtk-test.pl

from the command line.

A small window should open, with a Quit button inside.

Be the first to like.