Ken,

Many thanks for posting a reply with complete working code. Since posting I managed to find a work-around by adding a data string to the node entry in the tree, and then pulling the info later:

$string='Match'; # #define Itemstyles # $tree1_match_style = $tree1->ItemStyle('text', -foreground=>'green'); $tree2_match_style = $tree1->ItemStyle('text', -foreground=>'green'); # #add node to tree1 and tree2 # $tree1->add($indent0_line,-text=> $indent0_line,-itemtype=>'text'); $tree2->add($indent0_line,-text=> $indent0_line,-itemtype=>'text'); # #add style to node entry # $tree1->entryconfigure($indent0_line,-style=>$tree1_match_style); # #add data to node entry # $tree1->entryconfigure($indent0_line, -data =>$string); # #retrieve data from node # my $style_data=$tree1->infoData($indent0_line); # #retrieve style from node # my $wanted_style = $tree1->entrycget($indent0_line, q{-style}); # #print retrieved data and style # print "Tree1 style[$style_data]\n"; print "Tree1 wanted style[$wanted_style]\n"; # #configure style of node in tree2 # if ($style_data eq $string) { $tree2->entryconfigure($indent0_line,-style=>$tree2_match_style); }

When run the output is as follows:

Tree1 style[Match] Tree1 wanted style[Tk::ItemStyle=HASH(0x21dd6d4)]

However I've just used the pertinent lines from your post/code to shorten all the above to the follows, and it works a treat:

$string='Match'; # #define Itemstyles # $tree1_match_style = $tree1->ItemStyle('text', -foreground=>'green'); $tree2_match_style = $tree1->ItemStyle('text', -foreground=>'green'); # #add node to tree1 and tree2 # $tree1->add($indent0_line,-text=> $indent0_line,-itemtype=>'text'); $tree2->add($indent0_line,-text=> $indent0_line,-itemtype=>'text'); # #add style to node entry # $tree1->entryconfigure($indent0_line,-style=>$tree1_match_style); # # #retrieve style from node # my $wanted_style = $tree1->entrycget($indent0_line, q{-style}); # #configure tree2 node with retrieved style from tree1 node # $tree2->entryconfigure($indent0_line,-style=>$wanted_style);

The pertinent line in all this is the entrycget, and despite all my previous searching I was not aware you could retrieve the style of an item (hence my posting!)

Again, many thanks for taking the time and effort to reply and post a working script.


In reply to Re^2: PerlTk - How to retrieve the item style of a tree node? by Sicario
in thread PerlTk - How to retrieve the item style of a tree node? by Sicario

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.