#!/usr/bin/perl use warnings; use strict; use Tk; my @fruits = ("apple","pear","orange","starfruit","pineapple"); my @veggies = ("tomato","chard","spinach","beans","radish"); my @treats = ("chocolate","icecream","raspberries","pretzels","chips"); my %hash = ( fruits=> \@fruits, veggies => \@veggies, treats=> \@treats); my @sel = keys %hash; my $mw = MainWindow->new(); my $choice = 'apple'; my $selection = ''; my $bframe1= $mw->Frame()->pack(-side => "bottom"); my $bframe= $mw->Frame()->pack(-side => "bottom"); my $list = $bframe->Scrolled('Listbox', -listvariable => \@sel, -scrollbars=>'osoe', )->pack(-side=>'left'); my $list1 = $bframe->Scrolled('Listbox', # -listvariable => \@sel, -scrollbars=>'osoe', )->pack(-side=>'right'); my $om = $mw->Optionmenu( -options=> \@sel, -textvariable=>\$choice, -width=>'25', -command => sub{ @sel = @{$hash{$choice}} }, )->pack(-expand => '1'); $list->bind( '', sub { update( $_[0], $list1 ) } ); $list1->bind( '', sub { $selection = $_[0]->get( $_[0]->curselection ); # print "$sel\n"; } ); my $sel_label = $bframe1->Label( -textvariable => \$selection)->pack(); MainLoop; sub update { my ( $src, $dst ) = @_; my $index = $src->curselection; if ($index) { $dst->delete( 0, 'end' ); my $value = $src->get($index); foreach my $type(1..100){ $dst->insert( 'end', $value.$type ); } } }