Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: perl/Tk Entry widget displays wrong value when -textvariable is shared

by zentara (Archbishop)
on Sep 02, 2010 at 17:30 UTC ( #858613=note: print w/replies, xml ) Need Help??


in reply to perl/Tk Entry widget displays wrong value when -textvariable is shared

You are ecncountering a problem with threads:shared hashes where only the first level keys get shared by default. When you run as shared, the $top_hash{A}{B} gets ignored as being shared, while it runs fine in normal perl.

To amplify a bit, the Tk eventloop will never respond to a change in threads shared variables, when they are across thread boundaries. You don't have actual threads here, but you need to setup a timer, to read for any changes in the shared variable. So you can't use tied variables effectively across threads without timers. Try this:

#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; use Tk; my %top_hash; share $top_hash{'A'}{'B'}; $top_hash{'A'}{'B'} = 'Original'; my $t = MainWindow->new()->Scrolled('Text')->pack(); my $e = $t->Entry(-textvariable => \$top_hash{'A'}{'B'}); $t->windowCreate('end', -window => $e); $t->insert('end', "\n"); my $timer = $t->after(3000,sub{$top_hash{'A'}{'B'} = 'Changed'}); MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
  • Comment on Re: perl/Tk Entry widget displays wrong value when -textvariable is shared
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://858613]
help
Chatterbox?
[Lady_Aleena]: And the env variable $HOME doesn't work either. !@#$
[shmem]: no, that's a shell feature. Use $ENV{HOME}
[marioroy]: my $ans = qx{ find \$HOME -name "*.pl" -exec ls -l {} \\; };
[marioroy]: must backslash $ inside qx
[Lady_Aleena]: I haven't written perl for a while, I've been trying to do things at the command line. I'm having to relearn a lot.
[marioroy]: LA can you post the qx find again
[Lady_Aleena]: Things I would have written a script for while I was on Windows, I can run simply on the command line.
[Lady_Aleena]: marioroy, my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;); #unfixed

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-04-23 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.