in reply to tk form textvariables

IIRC Tk uses tied scalars for textvariables, so you need to update each scalar value in the hash separately. See the code below.

use Tk; my %current = (pilot => 'Harry'); my $mw = MainWindow->new; $mw->geometry('200x200'); my $ent = $mw->Entry( -textvariable => \$current{pilot}, )->pack; my $btn = $mw->Button( -text => 'New Pilot', -command => \&update, )->pack; MainLoop; sub update{ # This works $current{pilot} = 'Tom'; # This does not work %current = (pilot => 'Tom'); # So update the entire hash this way my %newstuff = (pilot => 'Tom', copilot =>'Dick', etc => 'Harry'); for (keys %newstuff){ $current{$_} = $newstuff{$_}; } }

Replies are listed 'Best First'.
Re^2: tk form textvariables
by liamlrb (Acolyte) on Mar 03, 2009 at 17:00 UTC
    tried your version but still seems to need the configure and update to work... here is the actually version ( %CURRENT is a globel variable that holds all the form variables
    $frm_current->BrowseEntry( -variable => \$CURRENT{PLATFORM_FIELD}, -width => 11, -font => $font, -background => $bgColor, -state => 'normal', -choices => [@PLATFORM_LIST] ), #etc ... sub displayFeed { # $path is from a Hlist path which is the key into hash my $path = shift; my %C = %{$FEEDS{$path}{formFields}}; # checked %C and %CURRENT and all values are present # after this loop for ( keys %C ){ $CURRENT{$_} = $C{$_}; } # still no update of the form after this update $mw->update; return
    Do I have to do the configure and update for every form field or am I still missing something ? I am just trying to create an easy way to store/recall and redisplay form fields. I am sure that this is a common problem with a well known solution. Am I taking the right track?
      Well I know yours works so I will start looking at any differences I can find.. thanks again

      Try using a hash reference:

      my %CURRENT = (PLATFORM_FIELD => ... my $hashref = \%CURRENT; ... $frm_current->BrowseEntry( -variable => \$hashref->{PLATFORM_FIELD}, -width => 11, -font => $font, -background => $bgColor, -state => 'normal', -choices => [@PLATFORM_LIST] ),
Re^2: tk form textvariables
by liamlrb (Acolyte) on Mar 03, 2009 at 16:32 UTC
    Got it.. thanks for everyone's response... I chose to learn perl because of Perl community's value of sharing, well represented in all the modules available and this site as well. I am not a full time programmer but I enjoy making mine, and other's jobs easier by trying to do it. Thanks again.