You are running into one of the limitations of using prebuilt widgets like the listbox. Highlighting selections have predefined meanings, and you just can't override them. The style of the 'active' element can be underlined or a dashed box around it. Color change is reserved for 'selected' items'. Look at this script, and remove the 'if entry press' conditional and see what happens..... the listbox needs a way to differentiate between the active and selected items, especially when the select mode is multiple. Now you can write your subclass of Listbox, and try to change the color definitions, but it is tricky because the mouse is also involved. You may want to look at the Tk::HList, which gives more control over the color schemes, with the 'style' options. In this example below, you may be able to selectionClear everything before setting the new selection, but then you lose multiple selection mode. It's tricky.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw=tkinit;
my @selects;
my $lb1 = $mw->Listbox->pack();
$lb1->insert('end',('A'..'J'));
$lb1->bind('<Enter>' => sub{ $lb1->focus });
$mw->bind('<KeyPress>' => sub {
$lb1->focus;
my $e = $lb1->XEvent; # get reference to X11 event struc
+ture
my $key = $e->K;
# comment out the if {} and see what happens
if( $key eq 'Return' ){
push @selects, $lb1->get('active');
$lb1->itemconfigure('active', -background => 'yell
+ow');
}
$mw->update;
print "@selects\n";
} );
MainLoop;