Radiobuttons that have the same -value and -variable are effectively the same button, even if there are dozens of instances.

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,$/;

In reply to Re^3: Tk: Dynamic Radiobuttons toggle problem... by keszler
in thread Tk: Dynamic Radiobuttons toggle problem... by iMisspell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.