Previous
Perl/Tk Tutorial, PDF 
Next
Contents 
Perl/Tk Tutorial - Create GUI with Perl's Tk Module
Perl/Tk Tutorial - Create GUI with Perl's Tk Module

Perl/Tk Tutorial - Create GUI with Perl's Tk Module

Perl Programming Republic. Perl/Tk Tutorial - Create GUI with Perl's Tk Module

Perl/Tk (also known as pTk) is a collection of modules and code that attempts to wed the easily configured Tk 8 widget toolkit to the powerful lexigraphic, dynamic memory, I/O, and object-oriented capabilities of Perl 5. In other words, it is an interpreted scripting language for making widgets and programs with Graphical User Interfaces (GUI).

Perl or Practical Extraction and Report Language is described by Larry Wall, Perl's author, as follows: "Perl is an interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for any system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal)."
The perlintro man page has this to say.

Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.

Tk, the extension(or module) that makes GUI programming in perl possible, is taken from Tcl/Tk. Tcl(Tool Command Language) and Tk(ToolKit) was created by Professor John Ousterhout of the University of California, Berkeley. Tcl is a scripting language that runs on Windows, UNIX and Macintosh platforms. Tk is a standard add-on to Tcl that provides commands to quickly and easily create user interfaces. Later on Tk was used by a lot of other scripting languages like Perl, Python, Ruby etc.

Applications

Perl has been used since the early days of the web to write CGI scripts, and is now a component of the popular LAMP (Linux/Apache/MySQL/Perl) platform for web development. Perl has been called "the glue that holds the web together". Large systems written in Perl include Slashdot, and early implementations of Wikipedia and PHP.

Perl finds many applications as a glue language, tying together systems and interfaces that were not specifically designed to interoperate. Systems administrators use Perl as an all-purpose tool; short Perl programs can be entered and run on a single command line.

Philosophy

Perl has several mottos that convey aspects of its design and use. One is There's more than one way to do it (TMTOWTDI - usually pronounced 'Tim Toady'). Another is Perl: the Swiss Army Chainsaw of Programming Languages. A stated design goal of Perl is to "make easy tasks easy and difficult tasks possible".

Perl is free software, and may be distributed under either the Artistic or the GPL License. It is available for most operating systems but is particularly prevalent on Unix and Unix-like systems (such as Linux, FreeBSD, and Mac OS X), and is growing in popularity on Microsoft Windows systems.

Perl/Tk Requirements

Before starting with the tutorial, make sure you have the following things. If some are missing you still can learn perl - but you will not be able to use it to its full power.

  1. ActivePerl from http://www.activestate.com/ActivePerl/ for windows - for programming in Windows. Linux don't need any special outside interpreter because it already has it in most of the distributions.
  2. A good text editor. I would recommend Crimson Editor(http://www.crimsoneditor.com/) for Windows and XEmacs for Linux.

Installing/Using Perl

In Unix/Linux you can execute your perl scripts by typing "perl <filename>" at command prompt. But before you do that make sure you have both Perl and its Tk module. Most linux distributions have perl - but quite a few don't have the Tk module. Make sure that the system you are using have the Tk module. If you don't have it, go to http://www.cpan.org and download the perl module. Or you can use the perl's CPAN module to install the Tk module. To do this, open a terminal and enter the following command
perl -MCPAN -e shell
cpan> install Bundle::CPAN
cpan> reload cpan
cpan> install Tk

Another(and a much easier) way to do this is to get a rpm of Perl/Tk and installing it with the command
rpm -ivh FILENAME

If you are using Ubuntu, a easy way of installing Perl/Tk is using this command...

sudo apt-get install perl-tk

If you are using Windows, download ActivePerl and install it. Then you can execute any perl file by double clicking it.

Two more things before we begin the tutorial. I will be teaching perl/tk and I expect you to know how to program in perl. I may ignore some of the perl coding conventions like including use strict;, -w or use warnings; in my examples. The examples have only one purpose - to demonstrate the feature that will be taught in that part of the tutorial. Sorry about that - but I have to keep my tutorial's example scripts short and to the point.

Finally, this is a tutorial for Perl/Tk only - I will not be teaching perl here. So if you know perl, continue. But if you are a beginner to perl, I would recommend that you read my perl tutorial.

Perl/Tk Tutorial - Create GUI with Perl's Tk Module
Author - Binny V A()
Bin-Co
Personal Site - BinnyVA.com

Previous
Perl/Tk Tutorial, PDF 
Next
Contents 
blog comments powered by Disqus
Subscribe to Feed