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

The Perl/Tk LabEntry Mega-Widget

Perl/Tk provides special code that combines a Label with an arbitrary widget, so you can have LabArbitrary widgets. This is fully explained in Chapter 14. Perhaps the most common of these labeled widgets is LabEntry. It’s configured using standard options, and ordinary options such as -font are directed to the Entry subwidget. To configure the Label subwidget, use options such as -labelFont, -labelBackground, and so on.

There’s a special option, -labelPack, that accepts a reference to a list of packer options and controls the relative geometry of the Label and Entry subwidgets. By default, the Label is packed on top of the Entry. If you prefer left-side packing, use -labelPack as in the example below. This example shows how to use a fixed-width font to create a column of aligned LabEntry widgets:

    foreach my $item (
      ['Copying', \$self->{file}],
      ['From', \$self->{from}],
      ['To', \$self->{to}],
      ['Bytes Copied', \$self->{bytes_msg}],
        ) {
        my $l = $item->[0] . ':';
        my $le = $cf_frame->LabEntry(
            -label        => ' ' x (13 - length $l) . $l,
            -labelPack    => [qw/-side left -anchor w/],
            -labelFont    => '9x15bold',
            -relief       => 'flat',
            -state        => 'disabled',
            -textvariable => $item->[1],
            -width        => 35,
        );
        $le->pack(qw/-fill x -expand 1/);
    }

Please refer to Chapter 14 for a complete list of -label options.

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