in reply to [Tkx] passing a variable to -value field in radio button

Please, fix the title of your post: replace Tk with Tkx.

It seems you think the value of the button is tied to the value of the variable, i.e. when the variable changes, the value of the button changes, too. But that's not the case, it's similar to

my $mode = 'old'; my $entry_mode = $mode; $entry_mode = 'new'; print $mode; # Still 'old'.

You need to configure the button to change its value every time the entry changes.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: [Tkx] passing a variable to -value field in radio button
by Anonymous Monk on Nov 22, 2017 at 09:05 UTC

    thanks for the answer, that confirms my thoughts

    I don't think i can change the title as I posted my message as anonymous :/

    the fix i used is to use -command => sub{$Mode = $OtherMode} but now the problem is the button is shown as unchecked if i click on it. Is there another way to do so? I can't find any example similar to what i wan on the internet :(

      What do you make of this? Its not unlike megawidgets

      #!/usr/bin/perl -- use strict; use warnings; use Tkx; Main( @ARGV ); exit( 0 ); sub Main { $Tkx::TRACE = 64; my $mw = Tkx::widget->new( "." ); my $f = $mw->new_ttk__frame(); my $textvar = RadiosEntry( $f, 'good', 'morning', 'sunshine' ); $f->g_pack; undef $f; $f = $mw->new_ttk__frame(); my $b = $f->new_button( -text => "Selection" ); $b->configure( -command => [ \&OnButtonTextFromTextvar, $b, $textv +ar ] ); $b->g_pack; $f->new_ttk__label( -text, 'yo', -anchor => "center" )->g_pack; $f->new_ttk__label( -textvariable => $textvar, -anchor => "center" + ) ->g_pack; $f->g_pack; Tkx::MainLoop(); } ## end sub Main sub OnButtonTextFromTextvar { warn "OnButtonTextFromTextvar @_"; my( $button, $textvar ) = @_; $button->configure( -text => join " ", 'Selection = ', $$textvar ) +; } sub RadiosEntry { my( $parent, @radios ) = @_; my $textvar = ""; my $selected; for my $radio ( @radios ) { my $button = $parent->new_ttk__radiobutton( -text => $radio, -value => $radio, ); $button->configure( -command => [ \&OnRadioButtonSetTextSetSelected, , $button, \$textvar, \$selected ], ); $button->g_pack; $radio = $button; ## modify @radios } ## end for my $radio ( @radios) my $ent = $parent->new_ttk__entry( -text => "", ); $ent->g_pack; $ent->g_bind( '<Key>', [ \&OnEntryConfigureRadioValueInvokeSelected, $ent, $radios[-1], \$selected ] ); return \$textvar; } ## end sub RadiosEntry sub OnEntryConfigureRadioValueInvokeSelected { warn "OnEntryConfigureRadioValueInvokeSelected @_"; my( $ent, $radio, $selected ) = @_; $radio->configure( -value, $ent->get ); $selected and $$selected->invoke; } sub OnRadioButtonSetTextSetSelected { my( $button, $textvar, $selected ) = @_; $$textvar = $button->configure( '-value' )->[-1]; $$selected = $button; warn "OnRadioButtonSetTextSetSelected @_ $textvar $selected\n"; } __END__

      See also https://www.tcl.tk/man/tcl/TkCmd/ttk_radiobutton.htm