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

Hello all!
Somebody know how I can get selected item in TList
what I do :
@sel= $tl->info('selection'); $selItem=$tl->get($sel[0]);
But the last command stuck the system with the folowing error message:
Use of inherited AUTOLOAD for non-method Tk::TList::get() is deprecate +d at /usr/local/lib/perl5/site_perl/5.005/sun4-solaris/Tk/Widget.pm l +ine 324.
Thanks,

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Tlist get selected
by Aragorn (Curate) on Sep 05, 2003 at 12:12 UTC
    According to Mastering Perl/Tk, the way to get the selection from a Listbox (and a TList) is
    @selected = $tl->curselection; foreach (@selected) { # Do something with the index: $selitem = $tl->get($_); }
    (I haven't tested the code, maybe your code barfs because the @sel list is empty).

    Arjen

Re: Tlist get selected
by bbfu (Curate) on Sep 05, 2003 at 23:02 UTC

    What do you mean by "get selected item"? What do you want to do with the result?

    I assume this is related to your previous question. If you want to know what directory or file the user clicked on, the @sel array in your code in this post should contain the file or directory. Try printing that directly to see what it contains, as in my example code in my reply to your other thread.

    If you're wanting to set or retrieve options associated with those items in the TList, you can use $tl->entryconfigure($sel[0], ...) and $tl->entrycget($sel[0], ...), respectively.

    bbfu
    Black flowers blossom
    Fearless on my breath