#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11118320 use warnings; use Tk; { # for package package Tk::ListBox2; use base qw/ Tk::Frame /; # Frame-based composite Construct Tk::Widget 'ListBox2'; # install MyNewWidget in pTk namespace sub ClassInit # called once to initialize new class { my($class, $mw) = @_; $class->SUPER::ClassInit($mw); } sub Populate # called to build each widget instance { my($self, $args) = @_; $self->SUPER::Populate($args); my $outer = $self->Frame()->pack(-fill=> 'both', -expand=> 1); $outer->Label(-text => 'A ListBox2', -fg => 'blue')->pack; my $inner = $outer->Listbox()->pack(-fill=> 'both', -expand=> 1); $outer->Label(-text => 'End of ListBox2', -fg => 'blue')->pack; $self->ConfigSpecs( DEFAULT => [$inner] ); $self->Delegates( Construct => $inner, insert => $inner, ); } } # end package my $mw = MainWindow->new; my $lb = $mw->ListBox2()->pack(-fill => 'both', -expand => 1); $lb->insert( 'end', 1 .. 10 ); MainLoop;