in reply to Re: PerlTk - How to retrieve the item style of a tree node?
in thread PerlTk - How to retrieve the item style of a tree node?

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.