#!/usr/bin/perl -w
######################################################################
# listbox.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use Tk;

my $top = MainWindow->new();

                            # create listbox
$listbox = $top->ScrlListbox(-label => "LIST", 
                             -height => 6,
                             -selectmode => "extended");

                            # buttons
$exitbutton   = $top->Button(-text => "Exit", 
                             -command => \&exit);
$selectbutton = $top->Button(-text => "Select", 
                             -command => \&proc_selection);

                            # display
$frame = $top->Frame(-relief => "sunken", 
                     -borderwidth => 2);
$label = $frame->Label(-text => "Selected: ");
$entry = $frame->Label(-textvariable => \$seltext, 
                       -relief => "sunken");

                            # pack all
$listbox->pack(-fill   => "both", "-expand" => "yes");
$exitbutton->pack(-side => "left");
$selectbutton->pack(-side => "left");
$frame->pack(-side => "right", "-anchor" => "se");
$label->pack(-side => "left");
$entry->pack(-side => "left");

                            # fill listbox
foreach $i (1..20) {
    $listbox->insert("end", "Item $i");
}
                            # set preselection
$listbox->selection("set", 0);
                            # simulate selection
$seltext = proc_selection();

                            # define action for double
                            # click on listbox entry
$listbox->bind("<Double-Button-1>" => \&proc_selection);

MainLoop;

###
### proc_selection() - process selection event
###
sub 
proc_selection {
                           # fetch selected entries,
                           # concatenate them to a string,
                           # and store them in the text
                           # variable of the label widget
   $seltext = join('  ', $listbox->Getselected);
}

