The following program is supposed to allow selection of all Tk::Tree items only on the second level. In other words, the user should only be able to select letters, not numbers. Since they obviously have to still be able to open/close the top level branches, the numbers cannot be in the disabled state. Therefore, when the user clicks on the numbers, I would simply like that selection to be cleared. However, when that happens, the background reverts to the undesired grayish color. For the life of me, I cannot figure out how to change that. Does anyone have any ideas?
use strict; use warnings; use Tk; use Tk::Tree; my $fgcolor = "#000000"; # foreground color my $bgcolor = "#FFFFFF"; # background color my $list_highlight_color = "#0099FF"; # list highlight color my $text_font = 'helvetica 12'; # Body text font my $title_font = 'helvetica 12 bold'; # Title text font my $mw = MainWindow->new(); $mw->optionAdd("*background", $bgcolor); $mw->optionAdd("*foreground", $fgcolor); $mw->optionAdd("*rotext*font", $text_font); $mw->optionAdd("*tree*font", $text_font); $mw->optionAdd("*entry*font", $text_font); my $tree; $tree = $mw->Scrolled('Tree', -font=>$text_font, -scrollbars=>'ose', - +selectmode=>'extended', -selectbackground=>$list_highlight_color, -hi +ghlightcolor=>$bgcolor, -drawbranch=>0, -browsecmd=>sub { foreach ($tree->selectionGet) { unless (/\./) { # do not allow selection of top level + items $tree->selectionClear($_); } } })->pack(-side=>'top', -fill=>'both', -expand=>1); for my $top ( 1 .. 3) { $tree->add( $top, -text => $top ); for ( 'A' .. 'C') { $tree->add( "$top.$_", -text => "$_" ); } } MainLoop();
In reply to Tk::HList selectionClear background problem by gri6507
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |