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.

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.