I want to select (higlight, activate) listbox entry when I click a
button.
$val_list =
$win->Listbox("width"=>25,"height"=>4,-foreground=>"blue",-background=>"whit
e",-exportselection=>0,-selectbackground=>"cyan")->pack(side=>"left");
$val_list->insert("end",@valfiles);
$val_list->bind("<Double-1>",\&get_val);
Can some one tell me how to enable an enry in the listbox.
Thanks in advance
> I want to select (higlight, activate) listbox entry when I click a button.
> Can some one tell me how to enable an enry in the listbox.
There's a difference between "activate" and "select" (see below).
Martin
#------------------------------------------------------------
use Tk;
my $count;
my $win = MainWindow->new();
$val_list = $win->Listbox(
-width => 25,
-height => 4,
-foreground => "blue",
-background=>"white",
-exportselection => 0,
-selectbackground => "cyan",
)->pack(
side => "left",
);
$win->Button(
-text => 'Print values',
-command => \&get_val,
)->pack(
side => 'bottom',
fill => 'x',
);
$win->Button(
-text => 'Select next entry',
-command => sub {$val_list->selectionSet($count++) },
)->pack(
side => 'bottom',
fill => 'x',
);
$win->Button(
-text => 'Activate next entry',
-command => sub { $val_list->activate($count++) },
)->pack(
side => 'bottom',
fill => 'x',
);
$val_list->focus;
@valfiles = (<*>);
$val_list->insert("end",@valfiles);
$val_list->bind("<Double-1>",\&get_val);
MainLoop;
sub get_val {
print "Active: ", $val_list->get(active), "\nSelected: ";
print $val_list->get($_), " " for $val_list->curselection;
print "\n";
};