Code Comments
Programming Forum and web based access to our favorite programming groups.If I understand correctly, I think he's embedding widgets, and probably
either binding them or setting up a callback for each one, and suddenly
there is the dilemma - assuming that the each widget has the same
callback or event handler code, how do you know which one in the list
was activated or triggered?
For what you're looking to do, there's a fairly easy way of handling
this: You pass the entry path as a parameter to each of the callbacks
or event handlers you set up. Here is a working demo. Is this something
like what you're trying to do?
Rob
use Tk;
use Tk::HList;
my $mw = MainWindow->new(-width => 360);
my $lab_orig = $mw->Label(-text => "test")->
pack(qw/ -expand 1 -fill both/);
## Create the Scrolled HList
my $list = $mw->Scrolled("HList",
-scrollbars => "osoe",
-background => "white",
-itemtype => 'window',
)->pack(qw/-expand 1 -fill both/);
## Add 10 entries, notice how I pass the "id" and $path to each callback
foreach my $i (1 .. 10) {
my $button = $list->Button( -text => "Button $i" );
my $path = $list->add($i, -itemtype => 'window', -widget => $button);
$button->configure(-command => [\&reportInfo, $list, $i, $path]);
}
MainLoop;
## THis subroutine demonstrates that the correct button is being
## invoked, and that I can access the $path in which the widget
## resides. I demonstrate by toggling the selection, just so that
## you can see something happening within the HList.
sub reportInfo {
my ($hlist, $id, $path) = @_;
print "Button $id pressed\n";
if ($hlist->selectionGet()) { $hlist->selectionClear(); }
else { $hlist->selectionSet($path); }
}
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.