Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Retrieving the value of an Selected Item from a Listbox widget

Reply
Thread Tools

Retrieving the value of an Selected Item from a Listbox widget

 
 
doni
Guest
Posts: n/a
 
      03-14-2007
Hi,

I would like to know how can I retrieve the value of the selected item
from the Listbox widget. I tried different options in Listbox widget
(<Double-ButtonPress-1>, <Return>) but I was not able to retrieve the
expected results.
Can anyone let me know how can I do this.

Thanks,
doni

#!/usr/bin/perl

use strict;
use Tk;

my @received_hello; my @sending_rupd; my @changing_l2; my
@received_nreg; my @received_nreg_new;
my @sending_nreg_ack; my @received_nd; my @received_nd_ack; my
@sending_nd; my @removing_l2;

my $mw = MainWindow->new;
$mw->configure(-title => 'Test Tool', -background => 'white', -width
=> "700", -height => "500");

my $lbox1 = $mw->Scrolled('Listbox', -scrollbars => 'osoe');
$lbox1->configure(-height => 8, -width => 20);
$lbox1->configure(-selectmode => 'browse');
$lbox1->pack(-anchor => 'e');

my $btn1 = $mw->Button(-text => "RFROUTED",
-command => \&rfrouted_button)->pack(-side =>
'right', -anchor => 'e');
my $btn2 = $mw->Button(-text => "GWD",
-command => \&gwd_button)->pack(-side =>
'right', -anchor => 'e');
my $btn3 = $mw->Button(-text => "Exit",
-command => sub{exit})->pack(-side => 'right', -
anchor => 'e', -after => $btn1);
my $fr = $mw->Frame(-background => 'cyan')->pack(-side => 'top', -
fill => 'x');
my $t = $mw->Scrolled("Text")->pack(-side => 'bottom', -fill =>
'both', -expand => '1');
MainLoop();

sub rfrouted_button {
repack();
foreach (qw/rcvd_hello sendg_rupd chng_l2 rcvd_nreg rcvd_nreg_new
sendg_nreg_ack rcvd_nd rcvd_nd_ack sendg_nd rmvg_l2/) {
$fr->Button(-text => $_, -command => \&rcvd_hello, -width =>
'12')->pack(-anchor => 'e');
}
}

sub gwd_button {
repack();
foreach (qw/new_device route_update/) {
$fr->Button(-text => $_, -width => '12')->pack(-anchor =>
'w');
no_of_times(@new_device);
}
}

sub repack {
$btn1->packForget();
$btn2->packForget();
$lbl1->packForget();
$lbl2->packForget();
}

sub rcvd_hello {
my @list = ("00:13:50:00:05:19", "00:13:50:00:05:bd",
"00:13:50:00:04:f9", "00:13:50:00:05:cb");
$lbox1->insert('end', @list);
$lbox1->bind('<<ListboxSelect>>',
sub{ display_lb_curselection($lbox1) });
}

sub display_lb_curselection {
my $lbox1 = shift;
my @cs = $lbox1->curselection();
my $selection = $lbox1->selectionSet(@cs);
print "Current choices: ", $selection;
print "\n";
}

 
Reply With Quote
 
 
 
 
doni
Guest
Posts: n/a
 
      03-14-2007
I was able to retrieve the value of the item selected from the Listbox
widget using get option.
Can anyone suggest me how can I do multiple selections from Listbox
widget..

On Mar 14, 10:48 am, "doni" <doni.se...@gmail.com> wrote:

> I would like to know how can I retrieve the value of the selected item
> from the Listbox widget. I tried different options in Listbox widget
> (<Double-ButtonPress-1>, <Return>) but I was not able to retrieve the
> expected results.
> Can anyone let me know how can I do this.
>
> sub rcvd_hello {
> my @list = ("00:13:50:00:05:19", "00:13:50:00:05:bd",
> "00:13:50:00:04:f9", "00:13:50:00:05:cb");
> $lbox1->insert('end', @list);
> $lbox1->bind('<<ListboxSelect>>',
> sub{ display_lb_curselection($lbox1) });
>
> }
>
> sub display_lb_curselection {
> my $lbox1 = shift;
> my @cs = $lbox1->curselection();
> my $selection = $lbox1->selectionSet(@cs);


Here is the change I made to the above line:
my $selection = $lbox1->get(@cs);

Thanks,
doni


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving the selected item from the dropdown list and storing it in a local variable yasodhai@gmail.com ASP .Net 6 03-08-2007 11:52 AM
Unable to get the selected item value of Listbox in codebehind akula.sandeepkumar ASP .Net 0 11-02-2006 01:04 PM
Return a value of the selected item from a dropdown listbox acord Javascript 1 03-09-2006 11:42 AM
Put value of a selected item in Listbox in a text field Eddy Scheire ASP General 6 01-31-2005 03:04 PM
Listbox NOT retrieving Selected Index Chris Thunell ASP .Net 3 07-28-2004 06:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57