Composite Mega-Widgets
There are several composite mega-widgets in the Perl/Tk distribution; DialogBox and LabEntry are two simple ones. Before we delve into derived mega-widgets, here’s a final, more complex composite.
Tk::Thermometer
This Thermometer widget is Frame-based and capable of displaying temperature in Kelvin, Celsius, or Fahrenheit. The default temperature scale is Kelvin, but is easily changed when the widget is instantiated.
my $therm = $mw->Thermometer( -label => 'Reactants Temp', -tscale => 'Celsius', )->pack; $therm->set(-273);
Figure 14-9 shows the results of these statements.
The mega-widget consists of a Scale widget packed on the left side of
the Frame and three Radiobuttons packed vertically on the right.
Instead of labeling the Radiobuttons with text, Pixmap images are
used. Notice that the entire mega-widget is a uniform, white
background color. This is because the configuration specifications
were cleverly devised so that the Frame, Scale, and Radiobuttons all
receive -background configure
requests. Other configuration specifications define the default look
of the mega-widget, from its width and height to the size of the
slider. The beauty of using configuration specifications is that none
of this is hardcoded in the mega-widget. Users are free to make
changes as they see fit, either during widget creation or in later
calls to configure
.
Figure 14-9. ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.