Retrieving the value of an Selected Item from a Listbox widget

Discussion in 'Perl Misc' started by doni, Mar 14, 2007.

  1. doni

    doni Guest

    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";
    }
    doni, Mar 14, 2007
    #1
    1. Advertising

  2. doni

    doni Guest

    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" <> 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
    doni, Mar 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Thunell

    Listbox NOT retrieving Selected Index

    Chris Thunell, Jul 28, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,142
    Chris Thunell
    Jul 28, 2004
  2. akula.sandeepkumar
    Replies:
    0
    Views:
    3,505
    akula.sandeepkumar
    Nov 2, 2006
  3. Replies:
    6
    Views:
    586
  4. Eddy Scheire
    Replies:
    6
    Views:
    257
    McKirahan
    Jan 31, 2005
  5. acord
    Replies:
    1
    Views:
    110
    Erwin Moller
    Mar 9, 2006
Loading...

Share This Page