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

Hi everyone I'm fairly new to perl as well as to this community (I couldn't use chatterbox). Anyway purpose of this post is: I want to use perlTk to create a window with Check Buttons when user hits next current window/frame should close to open new window/frame with few other check buttons. I've around 7 to 8 steps before user could press OK/Quit so its not convenient for user. Can anyone elaborate a bit Thank you

Replies are listed 'Best First'.
Re: perlTk opening new window
by Marshall (Canon) on Oct 24, 2010 at 04:54 UTC
    You can create additional windows.
    my $mw = MainWindow->new; my $newWindow = $mw->TopLevel();
    Use NewWindow just like the mainwindow.

    Creating these windows and getting them packed, etc takes a bit of time. So when I have a window like that, I just hide it when I'm done instead of "destroy". That way I can bring it back up on the screen very fast and it stays in the same place that the user had it. There are a number of methods to look at. to take off screen: withdraw() or perhaps iconify(), to get back: deiconify(), raise().

    Update: Good luck and re: CB look at CB clients. The java client runs in your browser and is easy to use although doesn't have all of the features of some of the others.

      Hey Marshall, Here is something I tried
      #!/usr/bin/perl use strict; use warnings; use Tk; my $win = new MainWindow; my $b1 = $win -> Button (-text=>"next", -command=>\&nextwin) -> pack() +; sub nextwin { my $win2 = $win->Toplevel(); my $b2 = $win2 -> Button (-text=>"quit", -command=>sub { exit }) -> pa +ck(); } MainLoop;
      well by this method I still have 2 windows on screen
Re: perlTk opening new window
by kcott (Archbishop) on Oct 24, 2010 at 05:14 UTC

    It sounds like one or more of the modules in the Tk::Wizard namespace is what you're after.

    -- Ken

      Thank you guys, I should look into these methods and reply back :) I appreciate quick response
Re: perlTk opening new window
by zentara (Cardinal) on Oct 24, 2010 at 21:58 UTC
    Without showing your code, we can only guess as to what you are actually doing. The advice to make new toplevel windows is ok, but you may find memory increasing for every new toplevel you create.

    It works basically like this. You need one Mainloop running, so you need to keep 1 mainwindow going, even if it is withdrawn from view. Once you have the Mainloop, you can create any number of toplevel windows controlled by that loop. If you start creating new toplevels, then destroying them, and you see memory gain, you can go to the more advanced method using packForget. You can take any window, withdraw it, run packForget on all it's packChildren, repack it with fresh widgets, then raise it back up. If you are going to juggle alot windows with different widgets packed into them, it is best to use the packForget method, so you have fewer windows created-destroyed.

    The idea is you can reuse existing windows. Furthermore, you can reuse any widgets by withdrawing them, reconfiguring them, then repacking them. Here is a basic example: (I didn't reuse the cb widgets, but reused the frame and maindow.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $top = new MainWindow; my @counts = ('a'..'z'); my %cbuttons; my $frame = $top->Frame()->pack(); setup_page(); $top->Button(-text => "packForget", -command => sub{ my @w = $frame->packSlaves; foreach (@w) { $_->packForget; } })->pack(); $top->Button(-text => "repack", -command => sub{ &setup_page })->pack(); $top->Button(-text => "Exit", -command => sub {exit})->pack; MainLoop; sub setup_page{ for (1..4){ my $text = shift @counts; $cbuttons{$_}{'cb'} = $frame->Checkbutton( -text => $text, -variable => \$cbuttons{$_}{'val'}, -command => \&SetState, )->pack; } }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Hey zentara, Thank you for your response. And sorry as of now I don't have code its just an idea. I wanted to take few parameters from user but parameters on window 3(consecutive window) are dependent on parameters chosen from window 2 so I wanted different windows for different parameters and its always good to have only one window open at a time so I asked this question. Your code explains it pretty neat I think if I incorporate method for button "ForgetPack" with "Next" that should work, I'll work on it over this week and let you guys know about code Thanks again :)