tags:

views:

1607

answers:

8

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options.

What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on.

+6  A: 

Try wxPerl!

From the web site:

wxPerl is an extension module allowing the creation of GUI (Graphical User Interface) from Perl; it is built as a wrapper for the awesome wxWidgets C++ GUI toolkit.

un-awesome, Alien::Wx is horrible, and not supporting file handle events is a deal breaker.
MkV
+8  A: 

Gtk2 has glade2 which can write out an XML file usable by Gtk2::GladeXML. Here is an example of how to bundle the XML with the app in the same file.

I misread the question at first. I thought you wanted a GUI editor for making GUIs (which is what glade2 is). You can also create GUIs using Gtk2 without glade2:

#!/usr/bin/perl

use strict;
use warnings;
use Gtk2;

Gtk2->init;

my $window = Gtk2::Window->new;
my $vbox   = Gtk2::VBox->new;
my $label  = Gtk2::Label->new("Hello World");
my $button = Gtk2::Button->new("Press me");

$window->add($vbox);
$vbox->add($label);
$vbox->add($button);

$window->set_default_size(200, 200);
$window->signal_connect(
    destroy => sub {
     Gtk2->main_quit;
    }
);

my $i = 0;
$button->signal_connect(
    clicked => sub {
     $label->set_text("button pressed " . ++$i . " times");
    }
);

$window->show_all;

Gtk2->main;
Chas. Owens
If you need a canvas with this Gnome2::Canvas is the heavyweight anser while Goo::Canvas doesn't have the gnome dependencies.
MkV
+6  A: 

Echoing Chas Owens, glade is quite usable with Gtk2 in Perl. In addition, Gtk2 also supports GtkBuilder files (which you can create the the latest glade too).

The main problem with wxPerl (and wxWidgets itself) is that it doesn't let you install file event watchers into its main loop (it only has GUI, Socket and Timer events), unlike Tk and Gtk.

The Qt, Tk and Gtk2 event loops can be used in Perl with AnyEvent, and Gtk2 can be hooked into applications running the Event or Ev mainloop with Glib::Event and Glib::EV modules.

MkV
Gtk2 also works with POE.
jettero
And POE can be used with AnyEvent, its just that POE is horrible in terms of memory usage and performance.
MkV
Really? s/perl/Perl/? I was referring to the binary.
MkV
+2  A: 

A GUI builder for WxPerl would be wxGlade or wxFormBuilder, both open-source.

MaxVT
+2  A: 

I would probably use Gtk2, but Tk is definitely not dead. The lack of releases is due to the bugs being ironed out over the years. A lot of people still use it, and it generally works fine. (Tk's event loop is somewhat silly, but that is a detail that probably shouldn't concern you.) The only disadvantage is that your GUI looks like it is from 1996, but who cares?

(The gitk tool included with git showed that Tk GUIs look fine as long as they're useful.)

jrockway
The gitk tool shows why nobody should be using Tk anymore, and I think - to answer the rhetorical question - pretty much everyone cares.
Telemachus
You think gitk looks fine? Oh, wait, you use linux on an 8 inch screen. :)
brian d foy
What I mean is that you can whine about the color of the GUI'sbackground all you want, the fact is that you still get your work doneeasily and efficiently. That means Tk is ugly, not dead.
jrockway
+1  A: 

I don't have a real answer for you, but often you have to consider your deployment targets. Some of the GUI libraries are very nice, but only if you can get them to work on your operating system. I don't necessarily think that all frameworks need to be cross-platform compatible, a very laudable goal to work toward in a perfect world, as long as the one you choose doesn't lock out a significant portion of your users because the foundation GUIs libraries are hard to install or support on a particular platform.

brian d foy
Wx, Tk, and Gtk2 are all cross platform, of the three Tk is the easiest to get working, followed by Wx, followed by Gtk2. In my experience the ease of coding goes in reverse order.
Chas. Owens
Wx is difficult to get working where there Alien::Wx doesn't work out of tarball (mostly operating systems with sharedlibrary.so.number.number, not sharedlibrary.so), which is strange since few other library using perl modules have that problem.
MkV
Gtk2 is cross-platform only in the sense that the word is meaningless. You either have to use someone's binary package, which pre-supposes something about your setup, or try to compile it yourself and give up.
brian d foy
A: 

The solution I'm going with is Gtk-Perl. At first I had difficulty installing it, but in the end I found Camelbox Perl+Gtk2 in one package.

mmccoo
A: 

I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.

PerlQt Wiki tutorial

PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.