Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Return value in Listbox

by FireBird34 (Pilgrim)
on May 13, 2009 at 14:41 UTC ( [id://763780]=perlquestion: print w/replies, xml ) Need Help??

FireBird34 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I'm playing around with Tk::Listbox, and am stuck on something. How do I return the selected item in the Listbox, evertime I click on said item? Everywhere I look, everyone has them set for button actions (which I don't want).

ie. when you select "dog" in the listbox, "dog" will be displayed in an Entry/Label widget. UPDATE: Please ignore my request. Was not thinking properly; used Bind to correct my problem.

Replies are listed 'Best First'.
Re: Return value in Listbox
by zentara (Archbishop) on May 13, 2009 at 16:26 UTC
    The button-1 of the listbox widget is internally bound in the c code, and hard to change behavior on. It is meant for selection. You probably will be better of using button-3 (right click) to avoid messing up things like multiple or extended selection mode.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $value; my $mw = MainWindow->new; my $entry = $mw->Entry( -state => 'readonly', -textvariable => \$value )->pack; my $lb = $mw->Listbox( -height => 0 )->pack; $lb->insert( 'end', qw/one two three four five six/ ); $lb->bind( '<ButtonPress-3>', [ \&setItem, \$value, Ev('@') ] ); sub setItem { my ( $lb, $valSR, $xy ) = @_; $lb->selectionClear( 0, 'end' ); my $index = $lb->index($xy); if ( defined($index) ) { $lb->selectionSet($index); $$valSR = $lb->get($index); } } MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://763780]
Approved by cosmicperl
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-24 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found