In short, you can get the style you want with:

my $wanted_style = $tree->entrycget($path_to_copy_style_from, q{-style +});

You haven't shown sufficient code for me suggest where you might have gone wrong; however, I've included a call to entryconfigure() (in the example code below) in case that's what was causing the problem.

Here's a working script that demonstrates a way to achieve what you want.

use strict; use warnings; use Tk; use Tk::Tree; use Tk::ItemStyle; my $mw = MainWindow->new(); my $style_t1 = $mw->ItemStyle(q{text}, -fg => q{red}, -bg => q{gold}); my $style_t1_2 = $mw->ItemStyle(q{text}, -fg => q{red}, -bg => q{white +}); my $indent0_line = 2; my $frame_t1 = $mw->Frame()->pack; my $frame_t2 = $mw->Frame()->pack; my $frame_b = $mw->Frame()->pack; my $tree_1 = $frame_t1->Tree(-itemtype => q{text})->pack; for (0 .. 3) { $tree_1->add($_, -text => qq{Line: $_}, -style => $style_t1); } $tree_1->entryconfigure($indent0_line, -style => $style_t1_2); my $tree_2 = $frame_t2->Tree(-itemtype => q{text})->pack; my $indent0_line_style = $tree_1->entrycget($indent0_line, q{-style}); for (0 .. 3) { $tree_2->add($_, -text => qq{Line: $_}, -style => $indent0_line_st +yle); } $frame_b->Button(-text => q{Exit}, -command => sub { exit })->pack; MainLoop;

-- Ken


In reply to Re: PerlTk - How to retrieve the item style of a tree node? by kcott
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.