Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: A node misplaced. . .

by Util (Priest)
on Jun 23, 2002 at 01:14 UTC ( [id://176558]=note: print w/replies, xml ) Need Help??


in reply to A node misplaced. . .
in thread Some beginning Tk help

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

  1. 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.
  2. 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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://176558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found