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

Hi Monks, I am facing a problem, creating and destroying(hiding) a frame, back n forth while pressing a button again n again. This frame is containing a table where data is entered, I want to retrieve that data as it is. Please help. Thanks kapsule
  • Comment on Perl/Tk:swapping of frames without loosing the data

Replies are listed 'Best First'.
Re: Perl/Tk:swapping of frames without loosing the data
by Erez (Priest) on Aug 12, 2008 at 08:41 UTC

    I doubt this part works:

    if (!Exists($show_table_frame))

    as the syntax is exists. You might want to use defined rather. Also, try not using our but rather define the variable outside the subroutine.

    Finally, all this is overkill, where you can simply use the following:

    if ($frame->ismapped) { $frame->packForget(); } else { $frame->pack(@{$frame->{PackInfo}}); }

    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.

      Thanks a lot.. It started working.
Re: Perl/Tk:swapping of frames without loosing the data
by Erez (Priest) on Aug 12, 2008 at 06:50 UTC

    I suggest posting some code here, so we could see what exactly is getting assigned to the frames and why is the content lost, or how to maintain it

    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.

      #!/usr/local/bin/perl use Tk; use Tk::Table; use Tk::Entry; my $mw = new MainWindow; my $title = $mw -> title("kapsule"); my $button = $mw-> Button(-text=>"show",-font => "verdanafont 10 bold" +,-command=>\&show_table)->pack(-side=>"top",-anchor => "w",-pady=>"15",-padx=>"5"); MainLoop; sub show_table() { if (!Exists($show_table_frame)) { our $show_table_frame = $mw->Frame()->pack(-side => "top",-fil +l => "both",-anchor => "nw",-padx=>"10"); our $show_table = $show_table_frame->Table(-columns => 3,-rows + => 5,-scrollbars => "o",-fixedrows => 1,-fixedcolumns => 0,-relief => 'raised',-takefocus=>"0",-pady=>"5"); my $tmp_label = $show_table->Label(-text => "Col. 1 ", -width +=> 15, -relief =>'ridge'); $show_table->put(0, 1, $tmp_label); my $tmp_label = $show_table->Label(-text => "Col. 2", -width = +> 15, -relief =>'ridge'); $show_table->put(0, 2, $tmp_label); my $tmp_label = $show_table->Label(-text => "col. 3", -width = +> 15, -relief =>'ridge'); $show_table->put(0, 3, $tmp_label); for($row=1;$row<5;$row++) { for ($col=1;$col<4;$col++) { my $ent = $show_table -> Entry(-font=>"verdana 10") + -> pack(-ipady=>"15"); $show_table->put($row,$col,$ent); } } $show_table->pack(); } else { $show_table_frame->destroy(); } }
      here is the code with which i am facing problem, i have tried pack and pack forget also.
        Try adding use strict; use warnings;.
        If u press button show, again and again frame will come and go, and any data in the frame will also be lost. I want that, data should not be lost. How to do that ? Any suggestions!! Please help..Monks! thanks in Advance
Re: Perl/Tk:swapping of frames without loosing the data
by Anonymous Monk on Aug 12, 2008 at 06:29 UTC
    don't create/destroy, create and pack/packforget
      thanx for quick reply... even pack and unpack is loosing the data... any other sugestion.....