Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need 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;

In reply to Re: A node misplaced. . . by Util
in thread Some beginning Tk help by dimmesdale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-19 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found