There are a few different problems here...
- PodMaster's reply is the answer to your main question: your "ok" button invokes exit; the program exits rather than returning from MainLoop; the final print statement is never reached. By following his advice ("ok" button destroys the window rather than exiting the program), you'll see the print-out. But also...
- In a Tk GUI, a Checkbutton can be turned on and off any number of times. The callback sub is called every time the user clicks the button (on or off), so the way your code is written, the user could stack the same file name onto @a multiple times, and if the final click turns the button off, the file name is still in the array.
- If the directory has a lot of text files, you'll end up creating a lot of Checkbuttons -- does your window layout support this? (For first-time Tk scripters, the answer is usually "no".)
- I assume the print @a at the end is just meant for debugging purposes, but it if there are two or file names in the array, they will be printed with nothing to separate them; try print "@a\n" instead -- placing the array in double quotes will cause the items to be printed with a space between them (space is the default value of "$," (output field separator -- see perldoc perlvar).
It would be better to use a Listbox widget to present file names (or even the ready-made Tk::FileSelect, though I think this sort of method is a pain for users). A simple Listbox scales well from just a few elements to hundreds, and it's easy to make it scrollable:
my $list = $mw->Scrolled('Listbox', ...);
(update: forgot to mention -- Listbox does support multiple selections, of course.)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.