in reply to perl tk Check button.

Here is a way to do it. There may be a better way, but this is pretty foolproof.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my @states = qw(Alaska Hawaii Michigan Georgia Arizona Washington Oreg +on 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 @cbvalues; my @cbnames; my $count = 0; foreach my $d( @states){ $cbnames[$count] = $d; $sp->Checkbutton(-text => $d, -font=>[arial => 12], -onvalue => 1, -offvalue => 0, -variable => \$cbvalues[$count], -font => 'big', -bg => 'white', )->pack(-anchor=>'w')->pack(); $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();

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: perl tk Check button.
by mailmeakhila (Sexton) on Apr 12, 2012 at 15:42 UTC
    Wow that was perfect. Can you refer any tutorial that i can follow for TK.
      There are many on google, but a few good ones are Tk tutorial, and uwinnipeg Tk tutorial. Also, there are 2 books available online, the oldest is Learning Perl/Tk, and the best is Mastering Perl/Tk. You can find sample chapters online, and the "Perl CD Bookshelf Version 3.0" ( an older version of the bookshelf) has 6 Perl books on it including Mastering Perl/Tk. A quick look at Ebay, has one for $22.50, pretty good for 6 Perl books. I don't know the legality of this site, but look at Mastering Perl/Tk

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        Thank you so much.