diarmuid has asked for the wisdom of the Perl Monks concerning the following question:

Hi

After banging my head against this yesterday I figured that this might be my best option to relieve the pain :-)

I am trying to write a simple wizard using perl/tk and specifically using the Tk::Wizard CPAN module. I have written a simple wizard that does nothing much but contains two pages. The problem is that when I select the Next page (frame) the Previous page is also kept. So in effect I have on page1 frame1 and on page2, frame1&frame2.

It took me a while to notice this as I had to resize the window to see the second frame after clicking Next.

Code is below and hopefully someone might have some idea as to what I am doing incorrectly.

Diarmuid


#!/usr/local/bin/perl5.8.3 -w use lib '/cdb/omap4ExtSetup/ind/lib/site_perl/5.8.3/'; use strict; use English; use Tk::Wizard; my $wizard = new Tk::Wizard; my %ocp_description; # MASTER OR SLAVE selection print $wizard->addPage( sub { page_one($wizard)} ) , "\n"; ## READ OR WRITE print $wizard->addPage ( sub { page_two($wizard)}), "\n"; $wizard->Show; MainLoop; exit; sub page_one { my $wizard = shift; $wizard->{backButton}->configure(-state=>'disable'); $wizard->{nextButton}->configure(-state=>'disable'); my $frame = $wizard->blank_frame ( -title => "Master or Slave Interface", -text => "Please select the type of interface on your module" +, -borderwidth => 2, ); my $slave_cb = &add_check_button($frame,"slave"); my $master_cb = &add_check_button($frame,"master"); $master_cb->configure (-command => sub { if ($ocp_description{master} == 1) { $slave_cb->configure(-state => 'disabled'); $wizard->{nextButton}->configure(-state=>'active'); }else{ $slave_cb->configure(-state => 'active'); $wizard->{nextButton}->configure(-state=>'disable'); } }); $slave_cb->configure (-command => sub { if ($ocp_description{slave} == 1) { $master_cb->configure(-state => 'disabled'); $wizard->{nextButton}->configure(-state=>'active'); }else{ $master_cb->configure(-state => 'active'); $wizard->{nextButton}->configure(-state=>'disable'); } }); $master_cb->pack(); $slave_cb->pack(); } sub page_two { my $wizard = shift; my $frame = $wizard->blank_frame ( -title => "Read or write", -text => "Does your module support the following", -borderwidth => 2, ); my $read_cb = &add_check_button($frame,"read"); my $write_cb = &add_check_button($frame,"write"); my $writenonpost_enable_cb = &add_check_button($frame,"writenonpost +_enable"); $write_cb->configure (-command => sub { if ($ocp_description{write} == 0) { $writenonpost_enable_cb->configure(-state => 'disabled'); }else{ $writenonpost_enable_cb->configure(-state => 'active'); } }); $read_cb->pack(); $write_cb->pack(); $writenonpost_enable_cb->pack(); } sub add_check_button { my $frame = shift; my $tag = shift; my $comment = shift; if (! defined $comment){ $comment = $tag; } my $cb = $frame->Checkbutton (-text => $comment, -variable => \$ocp_description{$tag}, ); return $cb; }

Replies are listed 'Best First'.
Re: Tk::Wizard not redrawing window correctly
by johngg (Canon) on Mar 07, 2007 at 11:10 UTC
    I'm glad you managed to solve your problem.

    Looking at your code I note that you use English;. You might want to change that to use English q{-no_match_vars}; to avoid a performance hit against any regular expression matching in your code. This is because once $' or $` ($PREMATCH and $POSTMATCH) are mentioned in a script it has an effect on all matches as pre- and post-match strings for any and all matches have to be saved since the perl interpretter has no way of knowing when they might be required. The English module will incur this performance penalty unless modified as suggested. Refer to perlre for more information.

    I hope this is of interest.

    Cheers,

    JohnGG

      Thanks John. I suspect the "use English" was there from a previous script :-)
Re: Tk::Wizard not redrawing window correctly
by diarmuid (Beadle) on Mar 07, 2007 at 08:51 UTC
    Typical. One day of looking at the problem and I discover the solution 10 mins after posting this. Oh well someone might find the solution helpful

    My problem was that I was not returning the frames from the subroutines.....

    so add

    return $frame;
    at the end of both page* sub routines fixes the problem