To get you started, Tk::HList (Tk::Tree) colors are best controlled by Tk::ItemStyle. So it's really a question of setting up your styles, and browsecmd, etc, to do exactly what you want. Here is an example I had handy.
#!/usr/bin/perl #------------------------ use strict; use Tk; use Tk::ItemStyle; use Tk::Tree; my $TK_top = MainWindow->new(); # create tree my $TK_tree = $TK_top->Scrolled( 'Tree', -background => 'white', -selectbackground => 'black', -selectforeground => 'hotpink', -scrollbars => 'osoe', -browsecmd => \&TK_tree_FileSelect, -command => \&TK_tree_FileSelect )->form( -left => '%0', -top => '%5', -bottom => '%70', -right => '%95' ); # create style for different colors my $Style_Red = $TK_tree->ItemStyle( 'text', -foreground => 'red', -background => 'white', -selectforeground =>'purple', ); my $Style_Blue = $TK_tree->ItemStyle( 'text', -foreground => 'blue', -background => 'white', -selectforeground =>'orange', ); my $Style_Green = $TK_tree->ItemStyle( 'text', -stylename => 'green', -foreground => 'green', -background => 'white', -selectforeground =>'cyan', ); my $Style_Black = $TK_tree->ItemStyle( 'text', -foreground => 'black', -background => 'white', -selectforeground =>'yellow', ); # create exit button my $TK_Button_exit = $TK_top->Button( -font => 'code' )->form( -right => [ '%100', '-20' ], -bottom => [ '%100', '-20' ] ); $TK_Button_exit->configure( -text => 'Exit', -relief => 'raised', -width => 30, -height => 1, -command => sub { exit; } ); PopulateTree(); MainLoop(); sub PopulateTree { my $entry; $entry = $TK_tree->addchild( "", -text => "RED", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Red ); $entry = $TK_tree->addchild( "", -text => "GREEN", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Green ); $entry = $TK_tree->addchild( "", -text => "BLUE", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Blue ); $entry = $TK_tree->addchild( "", -text => "BLACK", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Black ); $entry = $TK_tree->addchild( "", -text => "RED", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Red ); $entry = $TK_tree->addchild( "", -text => "GREEN", -data => "", -itemtype => 'text' ); $TK_tree->entryconfigure( $entry, -style => $Style_Green ); } sub TK_tree_FileSelect { my $entry = shift; if (@_) { my $style = $TK_tree->itemCget( $entry, 0, -style ); if ( $style eq $Style_Green ) { $TK_tree->configure( -selectbackground => 'gray45' ); } elsif ( $style eq $Style_Red ) { $TK_tree->configure( -selectbackground => 'red' ); } elsif ( $style eq $Style_Blue ) { $TK_tree->configure( -selectbackground => 'blue' ); } elsif ( $style eq $Style_Black ) { $TK_tree->configure( -selectbackground => 'black' ); } return; $TK_tree->update(); } }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Tk::HList selectionClear background problem by zentara
in thread Tk::HList selectionClear background problem by gri6507

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.