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

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.

A Frame-based Thermometer widget

Figure 14-9.  ...

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