Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

15.1. Looking at an Example Sideways

I admit it. I like examples. They give me a starting point to come back to when I'm getting into the nitty-gritty. Since there is quite a bit of nitty-gritty with composite widgets, we'll start simple and work up from there.

If you look at the code for these composite widgets, the LabEntry has the smallest amount of code. Here is the LabEntry.pm widget code:

# Copyright (c) 1995-1997 Nick Ing-Simmons. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
# Class LabeledEntry

package Tk::LabEntry;
require Tk::Frame;
@ISA = qw(Tk::Frame);

Construct Tk::Widget 'LabEntry';

sub Populate
{
 require Tk::Entry;
 # LabeledEntry constructor.
 #
 my($cw, $args) = @_;
 $cw->SUPER::Populate($args);
 # Advertised subwidgets:  entry.
 my $e = $cw->Entry();
 $e->pack(-expand => 1, -fill => 'both');
 $cw->Advertise('entry' => $e);
 $cw->ConfigSpecs(DEFAULT => [$e]);
 $cw->Delegates(DEFAULT => $e);
 $cw->AddScrollbars($e) if (exists $args->{-scrollbars});
} 

1;

That's the complete set of code, comments and all. You can tell it's a frame-based composite widget because of the line @ISA = qw(Tk::Frame). We can look in Programming Perl (O'Reilly, 1997) to find out what the @ISA array is for: "Within each package a special array called @ISA tells Perl where else to look for a method if it can't find the method in that package." There's a lot more there about how this implements inheritance, but I ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata