O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Hello, Perl/Tk

Tk is a module that gives you the ability to create graphical interfaces with Perl. Most Perl programs are written with command-line interfaces, which can be cumbersome and intimidating to end users. Perl/Tk lets you communicate with buttons, menus, dialog boxes, scrolled text areas, and so on—all the features you need to develop simple or sophisticated GUI applications.

Why use a graphical interface? In the course of your programming experience, you’ve probably come across situations in which a text-based interface was insufficient for your needs, if not downright awkward. Certain applications can run with no input, but others, such as installation scripts, require the user to feed information to them constantly. They ask such questions as: Do you want to install this file? Can I overwrite this DLL? Do you want to create this directory? Do you want the help files?

A graphical user interface (GUI) adds a little flair and professionalism to an application. Here are some examples of good uses for a GUI:

  • A mini web client that connects to a dictionary server

  • An application that displays a map in a scrollable window

  • A program that interfaces with a database and displays query results in several widgets, with labels to describe the data

  • A mail reader that interfaces with your inbox and can also send out mail messages

A GUI can also be helpful when your boss just says “make it easy to use!,” which usually means either adding a wrapper around a script or an interface that makes it easy for users to understand the decisions they have to make.

But don’t take this to mean that you should start adding GUIs to all your Perl scripts. There are times when it would be overkill to add a GUI to a script. If all you are doing is reading one file, munging a bit with no user input, and generating another file, a GUI would be silly and unnecessary. GUIs work best when you require a lot of decisions and input from the user, such as in the installation scenario mentioned earlier.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required