From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Daniel Burgaud Sent: Wednesday, May 08, 2013 12:11 AM To: Perl-Win32-Users Subject: TK Listbox problem; need help
> Hi, > Below is the script I have. > 1. Listbox is suppose to have 0-99 lines. working > 2. when user clicks on a line, it will highlight the line. working > 3. when user clicks on a particular line, script will display the value of that line to STDout. not working. > What happens is, it prints the value of the previous click!!! > Why? What is wrong? > > Dan. > > > > use strict; > use Tk; > require Tk::BrowseEntry; > require Tk::ROText; > > my $mw = MainWindow->new( -bg=> "#404040", -borderwidth=> 0); > $mw->minsize( 100, 200 ); > > > my $LB = $mw->Scrolled( > "Listbox", > -bg => "#C0C0C0", > -fg => '#000000', > -relief => 'raised', > -scrollbars => 'e', > -cursor => 'top_left_arrow', > )->pack( -side => 'top', -expand => 1, -fill => 'both', ); > $LB->bind('<Button-1>', sub { DoThis( $LB->get('active') ); } ); > > for (my $x=0; $x<100; $x++) { > $LB->insert('end',$x); > } > > sub DoThis { > my $this = shift; > print $this,"\n"; > } > > MainLoop; > It appears that the button callback is called before the 'active' member has been updated. You would be better off using something like: $LB->bind('<Button-1>', sub { DoThis( $LB->get($LB->curselection())); } ); HTH, Ken
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs