In this chapter, we become implementers and learn how to build specialized mega-widgets using Perl, the existing Tk widget set, and object-oriented (OO) techniques. We use the term mega-widget because the net result is usually a bigger, better, faster widget. There are two basic types of mega-widgets we are going to cover: composite and derived. They are very similar with only subtle differences between them, and for this reason, we refer to them collectively as mega-widgets.
A composite widget is essentially one widget that is composed of several other widgets contained in a Frame or Toplevel, and maybe some methods, bindings, and configuration options that perform specific functions. The widgets comprising a composite are often called subwidgets. For instance, a Dialog consists of two Label and several Button subwidgets contained in a Toplevel, but it’s neither Label-like nor Button-like. It’s in a class by itself, as it were.
A derived widget is a subclass of an existing widget, and differs from the widget it’s derived from by adding, changing, or subtracting functionality. It might also have different methods, bindings, and configuration options. For instance, ROText is a version of the Text widget with altered bindings that make the widget read-only (see Chapter 8).
But whether it is a composite or derived widget, our job as mega-widget writers is to make our new widget behave just like any other Tk widget, from how it’s ...