Monks I am again here hoping you can help me in my pursuit to learn Tk. I am creating a small program to create reports from various text files. The application first gives 3 different output types, then 2 different report types, and finally has a listbox of all the txt files in the directory. I am trying to pass all of this informatrion into a subroutine where I can start tracking the file changes. To test this I am just trying to get the value of the output, report_type, and listbox into the sub routine. The listbox valuse are fine, but the output type and report type is not changign with the radio buttons when I pass them. However outside of the subroutine the values do change with the radio buttons. Any suggestions on how to fix this? Here is the code.
use strict;
use Tk;
# Defaults
my $version = "change_tracker 0.5 beta";
my $output = "HTML";
my $report_type = "SHORT";
# Main Window
my $mw = MainWindow->new;
$mw->title("$version");
# Frames
my $label1_frame = $mw->Frame;
my $outputlist_frame = $mw->Frame;
my $label2_frame = $mw->Frame;
my $typelist_frame = $mw->Frame;
my $label3_frame = $mw->Frame;
my $files_frame = $mw->Frame;
my $exit_frame = $mw->Frame;
# Output Lablel
$label1_frame->Label(-text => "Type of Output")->pack;
# Output List
for ("HTML", "CSV", "TEXT") {
$outputlist_frame->Radiobutton(-text => $_,
-value => $_,
-variable => \$output)->pack(-side => 'left');
}
# Report Type Label
$label2_frame->Label(-text => "Report Type")->pack;
# Report Type List
for ("SHORT", "LONG") {
$typelist_frame->Radiobutton(-text => $_,
-value => $_,
-variable => \$report_type)->pack(-side => 'left');
}
# File Listing Label
$label3_frame->Label(-text => "Select Files to Track")->pack(-side =>
+'left');
# File Listing Listbox
my @files;
opendir DIR, "." or die "$!";
@files = sort grep /\.txt$/, readdir DIR;
closedir DIR;
my $listbox = $files_frame->Scrolled("Listbox",
-scrollbars => "oe",
-selectmode => "extended")->pack;
$listbox->insert('end', @files);
# Track Changes
$exit_frame->Button(-text => "Track",
-command => [ \&track_changes, ($listbox, $output, $report_typ
+e) ])->pack;
# Exit Button
$exit_frame->Button(-text => "Exit",
-command => sub { exit; })->pack;
# Pack Frames
$label1_frame->pack(-side => 'top', -fill => 'y');
$outputlist_frame->pack(-side => 'top', -fill => 'y');
$label2_frame->pack(-side => 'top', -fill => 'y');
$typelist_frame->pack(-side => 'top', -fill => 'y');
$label3_frame->pack(-side => 'top', -fill => 'y');
$files_frame->pack(-side => 'top', -fill => 'y');
$exit_frame->pack(-side => 'top', -fill => 'y');
# Main Loop
MainLoop;
sub track_changes {
my ($listbox, $output, $report_type) = @_;
my @files = $listbox->curselection;
for (@files) {
my $file = $listbox->get($_);
print "$file\n";
}
print "$output\n";
print "$report_type\n";
}
Any help you can offer would be very appreciated. Thanks!
-Prime