#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my @states = qw(Alaska Hawaii Michigan Georgia Arizona Washington Oregon California Texas Utah Minnesota); my $mw = tkinit(); $mw->geometry('300x300+100+100'); my $sp = $mw->Scrolled('Pane', -scrollbars=>'osoe', sticky=>'nwse') ->pack(-expand=>1, -fill=>'both' ); my %cbs; my @cbvalues; my @cbnames; my $count = 0; foreach my $d( @states){ $cbnames[$count] = $d; $cbs{$count} = $sp->Checkbutton(-text => $d, -font=>[arial => 12], -onvalue => 1, -offvalue => 0, -variable => \$cbvalues[$count], -font => 'big', -bg => 'white', )->pack(-anchor=>'w')->pack(); $cbs{$count}->bind('', sub{ print "@_\n"; print "do you 3rd state thing here\n"; }); $count++; } my $showbutton= $mw->Button(-text=>'Show Selected', -bg => 'lightyellow', -command => sub{ my @selected = (); foreach my $c( 0.. $count ){ if ( $cbvalues[$c] ){ push @selected, $cbnames[$c]; } } print "@selected\n"; } )->pack(); MainLoop();