in reply to Need a callback for Tk radio button deselect
#!/usr/bin/perl use Tk; my $mw = MainWindow->new; my $lastbutton = 0; my $rb1 = $mw->Radiobutton(-text => "Button One", -value => 'button1', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb2 = $mw->Radiobutton(-text => "Button Two", -value => 'button2', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb3 = $mw->Radiobutton(-text => "Button Three", -value => 'button3', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb2 = $mw->Radiobutton(-text => "Button Four", -value => 'button4', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; MainLoop; sub showRB { print "Arg list is @_\n"; my $state_ref = shift; my $state = $$state_ref; $mw->messageBox(-title => 'Status', -type => 'OK', -message => "Status is :$state:. Previous State +was $lastbutton"); $lastbutton = $state; }
|
|---|