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

how do i get my variable from listbox? I have
my($desk) = $root->Listbox (
-height => '0',
-setgrid => '1',
-width => '8',
);
when i try to do my $desk_val = $desk->get(); nothing is
gotten. if i print $desk it is a hash reference.

Replies are listed 'Best First'.
Re: perl/tk listbox
by {NULE} (Hermit) on Dec 17, 2001 at 05:33 UTC
      thanks this does the job just fine :)
Re: perl/tk listbox
by Beatnik (Parson) on Dec 17, 2001 at 04:37 UTC
    Altho I'm no Tk guru, I can tell you that the hash returning is quite normal. $desk is an instance of Listbox (which is a class if you will). Most object properties are stored in a hash. You can't directly print the object, you probably want to print some of it's values. I didn't find a get method in the method list (altho gtget comes pretty close. I'm sure some of the more Tk minded monks can help you along, hope this helps a bit...
    Ignore this please

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
(ichimunki) Re: perl/tk listbox
by ichimunki (Priest) on Dec 17, 2001 at 07:44 UTC
    If more than one item is selected, use:

    @selected = $lb->curselection

    to get a list of the index numbers for each selected item. Then use:

    $select_item = $lb->get( $selected[#] )

    If you know for a fact only one item is selected {NULE}'s method works.
Re: perl/tk listbox
by atcroft (Abbot) on Dec 17, 2001 at 19:35 UTC

    Since this is a place where multiple values are possible (as ichimunki pointed out in (ichimunki) Re: perl/tk listbox), instead of testing for the number of items then deciding if you're dropping them into an array or scalar, why not just put the values into an array then loop through them in either case? Doing that, if only one item were returned, it would be the first element-would it not? Anyone (especially if I am in error in my considerations)?