Your example code didn't run for us to easily modify, but here is an idea for reducing
or eliminating the iterations. You can pass extra info to the sub in the callback, which will clearly identify which button was pressed. You can make a hash element
unique to each radio button if you wanted, like a unique token, and pass that in to the callback.
Here is a simple example. For further help, make a small fully running code snippet for us to play with. Having to flesh out incomplete code examples, for testing, usually results in monks moving on to the next question.
#!/usr/bin/perl
use Tk;
my $mw = MainWindow->new;
my $rb = 'first button';
my $rb1 = $mw->Radiobutton(-text => "Button One",
-value => 'button1',
-variable => \$rb,
-command => [ \&showRB, \$rb, 1, 'man' ])-
+>pack;
my $rb2 = $mw->Radiobutton(-text => "Button Two",
-value => 'button2',
-variable => \$rb,
-command => [ \&showRB, \$rb, 2, 'auto' ])->pack;
MainLoop;
sub showRB
{
#print "Arg list is @_\n";
#print "@_\n";
my ($state_ref, $button_num, $type) = @_;
my $state = $$state_ref;
print "$state $button_num $type\n";
$mw->messageBox(-title => 'Status',
-type => 'OK',
-message => "Status is :$state: $type button $bu
+tton_num.");
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.