Perl/Tk programs are written in an object-oriented (OO) style, but you don’t need previous Perl object-oriented programming experience to code in Perl/Tk. You’ll pick it up easily enough after seeing the first few examples. In a nutshell, Perl/Tk widgets (such as Buttons and Listboxes) are objects that have methods we invoke to control them. Besides widgets, Perl/Tk has images, which are also objects, and fonts, which can be objects or simple strings.
A Perl/Tk program is composed of a hierarchy of widgets. At the top of the hierarchy is the MainWindow, the parent widget for all other widgets in the application. The MainWindow widget acts as a container, within which we arrange child widgets using a geometry manager. The widget hierarchy is important for several reasons. Among other things, it’s used by geometry managers to control the screen layout and the menu system to arrange menu items.
Each different widget belongs to a class. A widget’s class defines its initial appearance and behavior, but individual widgets of the same class can be customized. As an example, you might create two Buttons that have different textual labels but are otherwise identical. Sometimes you’ll read about instantiating a widget. This is simply OO-speak for creating a widget (a widget instance). The class constructor is responsible for creating widget instances.
The class also defines a widget’s initial behavior by creating bindings. A binding associates an event such as a button press with a callback, which is a subroutine that handles the event. You can add additional bindings (indeed, even change and remove them) to alter a widget’s standard behavior. Callbacks have several formats, but we mostly use simple references to Perl subroutines.
You’ll learn all about these topics as you continue reading.