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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: perl/Tk Entry widget displays wrong value when -textvariable is shared by zentara
in thread perl/Tk Entry widget displays wrong value when -textvariable is shared by Smile-n-Nod

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found