Instead of this being in the main part of your gui-creation code:
# Print Listbox Button my @filenames; my @selected_files = $listbox->curselection; for (@selected_files) { my $file = $listbox->get($_); push @filenames, $file; }
you need to put those lines into a subroutine (e.g. called "print_filenames"), and maybe change the comment to read "Callback function for the "Print Listbox Button".

Then, in the main part where you're declaring the other widgets, you need to actually create a Button widget that has something like "Print Chosen Files" as its text, and has this "print_files" sub as its callback.

I guess you want the button you have labeled as "Files" to do the actual printing job, so something like this should work for you (not tested) -- note that the "-command" attribute of the "Files" button is being given a reference to an anonymous array, whose elements are a reference to the callback function, followed by the arg being passed to that function (the arg is the handle for the listbox where the selection will come from):

... my $listbox = $files_frame->Scrolled("Listbox", -scrollbars => "oe", -selectmode => "extended")->pack; $listbox->insert('end', @files); $exit_frame->Button(-text => "Files", -command => [ \&print_filenames, $listbox ])->pack; $exit_frame->Button(-text => "Exit", -command => sub { exit; })->pack; ... sub print_filenames { # callback for the "File" Button my $listbox = shift; my @selected_files = $listbox->curselection; for (@selected_files) { my $file = $listbox->get($_); print "$file\n"; } }

In reply to Re: TK Listbox help by graff
in thread 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.