in reply to Re^2: Tk: Dynamic Radiobuttons toggle problem...
in thread Tk: Dynamic Radiobuttons toggle problem...
Putting Radiobuttons in different Frames does not group them; they are grouped by sharing the same -variable and distinguished within the group by different -values.
The -variable for the Radiobutton should be a reference to a scalar, e.g. \$something, \$hash{key}, \$array[6], etc. When the Radiobutton is selected - by the user or by calling $rdb->select - the -variable assigned to it is set to its -value. The reverse is also true: if the code sets the $something to a value matching a Radiobutton's -value, that Radiobutton becomes selected.
use strict; use warnings; use Tk; use Tk::Radiobutton; my $mw = Tk::MainWindow->new; my $rb_value; # undef, no Radiobutton selected $mw->Radiobutton(-text=>'first',-value=>'one',-variable=>\$rb_value)-> +pack(-anchor=>'w'); $mw->Radiobutton(-text=>'second',-value=>'one',-variable=>\$rb_value)- +>pack(-anchor=>'w'); $mw->Radiobutton(-text=>'third',-value=>'three',-variable=>\$rb_value) +->pack(-anchor=>'w'); $mw->Label(-text=>'------------------------')->pack; my $other_value = '0000ff'; # preset blue $mw->Radiobutton(-text=>'RED',-value=>'ff0000',-variable=>\$other_valu +e)->pack(-anchor=>'w'); $mw->Radiobutton(-text=>'GREEN',-value=>'00ff00',-variable=>\$other_va +lue)->pack(-anchor=>'w'); $mw->Radiobutton(-text=>'BLUE',-value=>'0000ff',-variable=>\$other_val +ue)->pack(-anchor=>'w'); MainLoop; print 'rb:',$rb_value,$/; print 'other:',$other_value,$/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Tk: Dynamic Radiobuttons toggle problem...
by iMisspell (Novice) on Feb 27, 2010 at 21:57 UTC |