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

Note: This has been solved, answers at end.

Hello monks, I have been working on a flat text database system in Perl (first year student project).
use strict; use Tk; my $mw = MainWindow->new; our $viewbox = $mw->Listbox(-height=>'30',-width=>'70')->pack(-expand= +>'1',-fill=>'both'); load($viewbox); MainLoop; sub load { my $idnum; my $tags; ($idnum,$tags) = (123,'tag1 tag2'); $viewbox->insert('end', "$idnum\t$tags"); }


I need some information about interfacing with Listboxes in Tk.

UPDATE: found I can get single line information using
my $entry = $viewbox->curselection; print $viewbox->get($entry)."\n";
SECOND UPDATE: $viewbox->delete('active') Deletes the currently selected entry. How I missed this, I have no idea..

THIRD UPDATE:
my @contents = $viewbox->get('0','end'); foreach (@contents) {print "$_\n";}
This enables you to read the entire listbox and print it out line by line.

I will leave all of this as a reference for SuperSearch, as it was not available for me to find earlier.

Thanks!

Replies are listed 'Best First'.
Re: Using a Listbox (Tk)
by halfcountplus (Hermit) on Mar 27, 2008 at 22:41 UTC

    hey, if you want to reduce your problem down to a much, much smaller example demonstrating the actual challenge then i will read it and might be able to help, because i'm not interested in your project per se but i can wield a list box.

    Consider how your question might look on an exam to you, vs. one that doesn't involve 100 lines of potential red herring.

      I apologize for the huge block of code. I have updated the OP to include only a basic Listbox, using delimited data. I appreciate your response, as others were also probably wary.
Re: *RESOLVED* Using a Listbox (Tk)
by zentara (Cardinal) on Mar 28, 2008 at 16:27 UTC
    I don't mean to slap you down, but just for future reference, to make you a better poster on Perlmonks.

    It would be nice if you posted this as a Reply Node to the original Node about Listboxes( which you have claimed to solve ). I understand the exhuberance you must feel to find out these solutions, but those things you mention are common knowledge amoung Tk users, and this just appears to me as a wasted node. We have all done this in the past, when we all were beginners, and had to report our findings to the world. (Even though the world already knows the answer).

    As far as not being able to find this earlier, groups.google.com is your friend. If you had searched there for example "perl Tk listbox delete" or "perl Tk listbox get selections" you would have found hundreds of examples to do what was needed.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum