in reply to Tk Checkbutton
#!/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 %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('<ButtonRelease-3>', 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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk Checkbutton
by ak.arjun (Initiate) on Apr 25, 2012 at 05:34 UTC | |
by Anonymous Monk on Apr 25, 2012 at 06:04 UTC |