Hello monks! I have just recently started learnign how to use Tk and I am already stuck on a problem. I have a listbox that lists the textfile names in the current directory. However I can not seem to figure out how to get the users selection from that list box. Here is what I have so far.
#!perl -w use strict; use Tk; # Main Window my $mw = MainWindow->new; # Frames my $label3_frame = $mw->Frame; my $files_frame = $mw->Frame; my $exit_frame = $mw->Frame; # File Listing Label $label3_frame->Label(-text => "Select Files to Track")->pack(-side => +'left'); # File Listing Listbox my @files; push @files, $_ for <*.txt>; my $listbox = $files_frame->Scrolled("Listbox", -scrollbars => "oe", -selectmode => "extended")->pack; $listbox->insert('end', @files); # Print Listbox Button my @filenames; my @selected_files = $listbox->curselection; for (@selected_files) { my $file = $listbox->get($_); push @filenames, $file; } $exit_frame->Button(-text => "Files", -command => sub { print "@filenames\n"; })->pack; $exit_frame->Button(-text => "Exit", -command => sub { exit; })->pack; # Pack Frames $label3_frame->pack(-side => 'top', -fill => 'y'); $files_frame->pack(-side => 'top', -fill => 'y'); $exit_frame->pack(-side => 'top', -fill => 'y'); # Main Loop MainLoop;
The @selected_files array is never getting populated with any of the selections. Any help you can offer would be very appreciated. Thanks!

-Prime

In reply to TK Listbox help by PrimeLord

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.