Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I am having troubles in dynamically creating Tk entries fields tied to values from a hash and updating such entries when the hash changes. I have created a simple script to show the problem. After clicking on "Update" the hash is updated, but no changes in the Tk fields. What am I doing wrong?
use strict; use warnings; use Tk; my $mw = tkinit; $mw -> geometry("200x200"); our %MyValues=("1", "term1", "2", "term2", "3", "term3"); for my $DBcolumn (1..3) { $mw->Entry(-textvariable => \$MyValues{$DBcolumn},-justify +=>"left",-width => 25)->pack(-side => 'top', -anchor => 'w'); } my $button1 = $mw->Button(-text => 'Update Values', -command => +\&LoadNewValues)->pack(); my $button2 = $mw->Button(-text => 'Print Out Content', -command + => \&PrintOutContent)->pack(); MainLoop(); sub PrintOutContent{ print "$MyValues{1} $MyValues{2} $MyValues{3}\n"; } sub LoadNewValues{ %MyValues=(); %MyValues=("1", "hallo", "2", "ok", "3", "fine"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Updating Tk Entries with Hash
by AnomalousMonk (Archbishop) on Dec 31, 2016 at 19:13 UTC | |
|
Re: Updating Tk Entries with Hash
by Marshall (Canon) on Dec 31, 2016 at 22:44 UTC | |
|
Re: Updating Tk Entries with Hash
by kcott (Archbishop) on Jan 01, 2017 at 00:56 UTC | |
|
Re: Updating Tk Entries with Hash
by Anonymous Monk on Dec 31, 2016 at 12:49 UTC | |
|
Re: Updating Tk Entries with Hash
by Anonymous Monk on Jan 02, 2017 at 10:33 UTC |