in reply to PerlTk - How to retrieve the item style of a tree node?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PerlTk - How to retrieve the item style of a tree node?
by Sicario (Initiate) on Feb 13, 2012 at 12:34 UTC |