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

What’s in This Book

Here is the breakdown of what we cover in this book:

Chapter 1

The first chapter contains some interesting history about the Tk module, introductory comments, and the obligatory Hello World program.

Chapter 2

Geometry management is probably the most important concept in using Perl/Tk. It determines how your widgets are drawn on the screen. Four geometry managers—pack, grid, place, and form — are covered here. Most of the examples in the book use pack.

Chapter 3

You can easily make effective use of fonts in your Perl/Tk applications using Font objects. This chapter shows you how to utilize Fonts and what options are available for changing them. Several small applications are covered that demonstrate the use of Fonts.

Chapter 4

The Button widget is the first we cover, and we supply lots of details. There are tons of code snippets and screen shots showing different ways to manipulate the Button widget. Many of the options we discuss are common among the other standard widgets. In addition to the standard Button widget, we’ll look at two derived variants: the Checkbutton and Radiobutton widgets.

Chapter 5

The Label widget is the simplest of all. It is usually used with an Entry widget, which is why they are included in the same chapter. Typically, the Entry widget accepts user input, and the Label identifies the input. Perl/Tk has a special Tk::LabEntry widget that we’ll examine in detail.

Chapter 6

Certain widgets in Perl/Tk can be scrolled, which means they can contain more information than you can see on the screen. Scrollbars are used to navigate the data inside these widgets. This chapter tells you how Scrollbars communicate with each widget and how to create and use them. It also illustrates the Scrolled method, which automates Scrollbar creation.

Chapter 7

A Listbox widget can contain any sort of data, but it usually contains a list of options from which the user can select. In this chapter, you’ll learn how to create a Listbox, fill it with some items, and change the way the user selects items from the list.

Chapter 8

The Text widget is a versatile widget you can use for many purposes besides just displaying text. This chapter covers the different things you can put inside a Text widget (such as text, images, or other widgets) and how to get the best use out of them. The derived TextUndo and ROText (Read-Only Text) widgets are also discussed.

Chapter 9

A Canvas widget can display objects such as circles, rectangles, text, images, and even other widgets. This chapter covers all the options and methods available, and shows how to use them.

Chapter 10

The Scale widget is great for giving the user a range of numbers from which to select so that users can’t type in numbers out of range or type in letters accidentally. This chapter includes examples of the Scale widget and covers all the methods available for setting it up and using it.

Chapter 11

The Frame and Toplevel widgets are used to organize your other widgets on the screen to get the look you want. This chapter shows how you can use Frames and Toplevels in coordination with a geometry manager (covered in Chapter 2) to make your windows look the way you want them to. We also look closely at the MainWindow, which is a specialized Toplevel in disguise.

Chapter 12

Once an application gets complex enough, you will need to put a Menu in it. This chapter shows different ways to create menubars and pulldown, popup, tearoff, and option menus, and how they can best be used in an application. We also cover menu virtual events and briefly examine pie menus.

Chapter 13

There are many methods available for all widgets in Perl/Tk. We cover them in this chapter and show you how to use them. The two most important of these methods are configure and cget.

Chapter 14

Creating custom widgets is sometimes the only answer to a problem. This chapter covers all the details, including the Tk class hierarchy, and gives you several examples of composite and derived mega widgets to examine. You will find details here that appear nowhere else in the known universe. Featured widgets are Tk::Nil, Tk::CanvasPlot, Tk::LabOptionmenu, Tk::LCD, Tk::NavListbox, Tk::Thermometer, Tk::CollapsableFrame, and Tk::MacCopy.

Chapter 15

This chapter explores the inner workings of Tk’s event loop, including timers, I/O, mouse and keyboard events, bindings, and callbacks. Featured modules are Proc::Killfam, Tie::Watch, Tk::Trace, Tk::bindDump, and Tk::waitVariableX. Featured widgets are Tk::ExecuteCommand, Tk::MacProgressBar, and Tk::Splashscreen.

Chapter 16

This chapter describes how to use the comand line and option database to customize your Perl/Tk application.

Chapter 17

This chapter covers the various image types and how to use them. We examine Bitmaps, Pixmaps, Photos, and compound images, and touch on tile, transparency, and animation issues. Featured widgets are Tk::Animation, Tk::PhotoRotateSimple, Tk::Thumbnail, and Tk::WinPhoto.

Chapter 18

A detailed look at all the Tix widgets and ways to use them effectively in Perl/Tk applications, including display items and display styles.

Chapter 19

With care, pipes and sockets can coexist with Tk’s event loop. This chapter develops two illustrative client/server programs.

Chapter 20

Tk provides an unusual IPC mechanism that allows Tk programs to send messages amongst themselves. This chapter describes Perl-Perl, Tcl-Tcl, and Perl-Tcl intercommunications, and discusses security considerations. We compute π with multiple processes and develop a Perl plug-in for tclrobots so that Perl and Tcl Robot Control Programs can do battle. Featured modules include Tk::Receive and Tk::TclRobots.

Chapter 21

This chapter shows how to write, debug, and package a Tk widget written in C, using the Tk::Square widget as an example.

Chapter 22

LWP is a Perl library for accessing the World Wide Web. This chapter develops a web client, tkcomics, that displays our favorite comic strips. It details various nonblocking mechanisms for both Unix and Win32. Featured modules are LWP::Simple, LWP::UserAgent, and Tie::Win32MemMap. We then describe the PerlPlus Netscape plugin, which allows you to embed Perl in Netscape and run client-side programs.

Chapter 23

This chapter is a grab-bag of miscellaneous information and simple widgets such as Adjuster, Balloon, BrowseEntry, ColorEditor, Dialog, DialogBox, ErrorDialog, LabFrame, NoteBook, Pane, ProgressBar, chooseColor, getOpenFile, getSaveFile, and messageBox.

Appendix A

The Tk module doesn’t come with the standard Perl distribution. This appendix tells you where to download the latest release and updates, and how to install them.

Appendix B

This appendix lists all the options for every widget described in this book.

Appendix C

This appendix includes complete code listings of sample programs that don’t appear in the book proper.

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