Hello Monks,

I searched here for Tk::Tree and did not find a relevant article, CPAN, and O'Reilly ... but the answer is elusive.

I am able to populate a Tk::Tree with a structure, and after some processing, I would like to change the color of an entry is the tree - but I can't get the call and syntax right.

Here's the sample Tk::Tree code:

use Tk; use Tk::Tree; my $mw = MainWindow->new(-title => 'Tree'); my $tree = $mw->Tree->pack(-fill => 'both', -expand => 1); foreach (qw/orange orange.red orange.yellow green green.blue green.yel +low purple purple.red purple.blue/) { $tree->add($_, -text => $_); } # Different things to try here $tree->autosetmode(); MainLoop;
1. Try itemConfigure:
$tree->itemConfigure('orange.red', 0, -foreground => 'blue');
Error:
Bad option `-foreground' at C:/Strawberry/perl/site/lib/Tk.pm line 251 +.
2. Try itemConfigure with a '1' since altering orage.red would be in column 1 of a HList:
$tree->itemConfigure('orange.red', 1, -foreground => 'blue');
Error:
Column "1" does not exist at C:/Strawberry/perl/site/lib/Tk.pm line 25 +1.
3. OK. Try option -fill instead of -foreground because of other observed inconsistencies in Tk:
$tree->itemConfigure('orange.red', 0, -fill => 'blue');
Error:
Bad option `-fill' at C:/Strawberry/perl/site/lib/Tk.pm line 251.

I've tried configure, itemConfigure, entryConfigure (that's for menus) and I'm just not getting it right.

Please help!


In reply to Tk::Tree how to set color of entry after tree creation by EnzoXenon

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.