in reply to Tk::Tree how to set color of entry after tree creation

Finding the documentation is a bit tricky. You need to read the following paragraph in Tk::Tree:
The Tree class is derived from the HList class and inherits all the methods, options and subwidgets of its super-class.

And Tk::HList shows what we need to do:

Each list entry in an HList widget is associated with a display item. The display item determines what visual information should be displayed for this list entry. Please see Tk::DItem for a list of all display items.

Having read Tk::DItem, we can now solve the problem:

#! /usr/bin/perl use warnings; use strict; use Tk qw{ MainLoop }; use Tk::Tree; use Tk::ItemStyle; my $mw = 'MainWindow'->new(-title => 'Tree'); my $tree = $mw->Tree->pack(-fill => 'both', -expand => 1); $tree->add($_, -text => $_) for qw( orange orange.red orange.yellow ); my $blue = $tree->ItemStyle('imagetext', -foreground => 'blue'); $tree->itemConfigure('orange.red', 0, -style => $blue); MainLoop();

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Tk::Tree how to set color of entry after tree creation
by EnzoXenon (Acolyte) on Feb 02, 2024 at 12:28 UTC
    Thank you - a most excellent answer!

    I missed the HList doc referring to the styles (probably out of frustration but also possibly due to lack of ability to read when interrupted constantly, but I digress), which work perfectly.

    Thanks for the assist!