display | more...

"Perl/Tk" is a library of modules so that perl can use John Ousterhout's Tk toolkit without having to go through the hassle of learning tcl. With perl/tk, a perl programmer can hack up quick and dirty windowing apps.

The faq is at:

By far the oldest and most popular graphical library used with perl, it is also the most portable, currently running on Un*x, Win32 and Mac OS.

When people first wanted to write graphical applications in perl, the Tk widgets seemed a natural choice to use, as they were comprehensive, easily extensible, and ideally suited to the sort of quick-and-dirty programming that perl was mostly used for at the time. The trouble was that Tk appearred to be irrevocably stuck to everyone's least-favourite scripting language, Tcl, by means of the Tcl Windowing Shell (wish).

The first graphical perl applications were written by Malcolm Beattie, using a perl-4 library that enabled Tcl commands to be embedded in a perl script. Although this worked, it was also an obvious kludge - it still required a basic knowledge of Tcl in order to program, and also still required the wish binary to be installed on the system.

The advent of perl-5 added the ability to communicate directly with C function libraries using the Extension Subroutines (XS) system. This allowed for a cleaner approach to the graphics problem, and Nick Ing-Simmons set about divorcing Tk from Tcl. He first separated out all the sections of the Tk/wish source code that dealt directly with the graphical interface, and with a bit of work was able to compile these routines into a language agnostic library which he called "Portable Tk" (pTk). This library provided a complete implementation of the Tk widget set that was totally independent of Tcl. He then used the XS system to write a set of perl bindings for pTk, and parcelled the two parts together into the perl/Tk package which he submitted to CPAN.

The current version of perl/Tk is 800.023. This is a compete re-implementation of the Tk8.0 widget set, with a few extras from the Tix extensions to Tk added. It is not necessary to have any version of the Tcl/Tk programs or libraries installed in order to use it - the complete source code for pTk is included in the CPAN package. It should be noted that although the perl modules that provide the Tk interface are distributed under the same terms as perl itself (i.e. disjunction of the GPL and Artistic licenses), the pTk library is distributed under a BSD-style license due to its derivation from the original Tk.

Finally, as an example, here's "Hello, World" in perl/Tk:


use warnings;
use strict;
use Tk;

my $main = MainWindow->new;
$main->Label(-text => 'Hello, world!')->pack;
$main->Button(-text => 'Quit',
              -command => [$main => 'destroy']


Sources: perldoc Tk and the comp.lang.perl.tk FAQ

Log in or register to write something here or to contact authors.