#!/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(); } }
In reply to Re: Tk::HList selectionClear background problem
by zentara
in thread Tk::HList selectionClear background problem
by gri6507
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |