I couldn't figure out how to update the node
See How do I change/delete my post?
Would all that would be required to do this be to undraw the current screen (via the forget method?) and then re-draw with the desired buttons
- I think (but have not verified) that just using gridForget or packForget would cause a memory leak, for they only remove the widget from screen management; they don't actually get rid of the widget. Calling destroy does both.
- You only have to destroy and recreate the affected widgets, if they are all in one Frame or other pack-able container; no need to do the whole screen.
Other than that, you are correct. Here is an implimentation:
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::Pane;
my $mw = MainWindow->new( -title => "SACL Survey" );
my $pane = $mw->Scrolled(qw/Pane -scrollbars osow/)->pack(
-expand => 'yes',
-fill => 'both',
);
my $frame = $pane->Frame->pack();
$mw->Label( -text => "... <insert directions here> ..." )->pack();
my @button_values;
my @frame_widgets;
sub button_set {
my $i = int(shift);
my $prev = $i - 1;
my $next = $i + 1;
my $first = 1;
my $last = 30;
$prev = $first if $prev < $first;
$next = $last if $next > $last;
$_->destroy foreach reverse @frame_widgets;
@frame_widgets = ();
push @frame_widgets, $frame->Label(
-text => "Survey Question #$i",
)->pack();
push @frame_widgets, $frame->Button(
-text => "First",
-command => sub { button_set($first) },
)->pack(
-side=>'left',
);
push @frame_widgets, $frame->Button(
-text => "Back to $prev",
-command => sub { button_set($prev) },
)->pack(
-side=>'left',
);
foreach my $j (1..4) {
push @frame_widgets, $frame->Radiobutton(
-text => $j,
-value => $j,
-variable => \$button_values[$i-1],
)->pack(
-side => 'left',
);
}
push @frame_widgets, $frame->Button(
-text => "Forward to $next",
-command => sub { button_set($next) },
)->pack(
-side => 'left',
);
push @frame_widgets, $frame->Button(
-text => "Last",
-command => sub { button_set($last) },
)->pack(
-side => 'left',
);
}
button_set(1);
MainLoop;
use Data::Dumper;
print Dumper \@button_values;