Hi,
I have an entry widget which has a binding for "<Key-Return>" and I have
a listbox widget which has a bidning for "<<ListboxSelect>>".
Both bindings work OK: if I enter something into the entry widget, it
runs the handler, if I select a listbox entry uwing the mouse, it fires
the handler. However, when I call "selectionSet()" from the entry
widget's "<Key-Return>" handler with the index of an entry in the
listbox, the "<<ListboxSelect>>", the "<<ListboxSelect>>" virtual event
is not generated.
From the man page, I inferred that it should have been: "Any time the
selection changes in the listbox, the virtual event <<ListboxSelect>>
will be generated."
The following shows what I mean:
If you click on an entry in the list, the text appears at the bottom.
If you enter an entry's text, the entry will be selected, but the label
will not be modified.
What am I doing wrong?
Josef
#! /usr/bin/perl
use warnings;
use strict;
use Tk;
my $top = new MainWindow;
my $ent = $top->Entry(-width => 10)->pack(-side => 'top');
my $list = $top->Listbox(-height => 5, -selectmode =>
'browse')->pack(-side => 'top');
my $lab = $top->Label(-text => 'XXX')->pack(-side => 'top');
$ent->bind('<Key-Return>' => [ \&search, $ent, $list ]);
$list->bind('<<ListboxSelect>>' => [ \&show, $list, $lab ]);
$list->insert('end', $_) foreach ('A', 'B', 'C', 'D', 'E', 'F');
MainLoop;
sub search {
my ($self, $ent, $list) = @_;
my $listlen = $list->size;
my $pat = $ent->get();
for (my $n = 0; $n < $listlen; $n++) {
my $item = $list->get($n);
if ($item =~ /$pat/) {
$list->selectionSet($n);
last;
}
}
}
sub show {
my ($self, $list, $lab) = @_;
my $idx = $list->curselection;
my $text = $list->get($idx);
$lab->configure(-text => $text);
}
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details:
http://de.ts.fujitsu.com/imprint.html