Re: Forgetting and Recalling widgets
Ala Qumsieh <[email protected]> Wed, 12 Sep 2007 09:11:24 -0700 (PDT)
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
why not just re-grid the same widget again? That will give you what you want. gridForget doesn't destroy your widget. It just unmaps it from the window. To remap it, grid it again. --- Henry Merryweather <[email protected]> wrote: > I want to selectively hide and then recall widgets > and when I recall the > widget it would be good if the widget was exactly > the same as when it was > hidden. > = > gridForget hides the widget. However, I cannot see > a way of simply > recalling the widget with its contents the same as > when it was =91forgotten=92. > = > = > = > I tested this with the Perl code below and attached. > This gives two columns > where each column is: > = > 1. an Entry box at the top > 2. a Button to remove the Entry box at the top > 3. a Button to recall the Entry box at the top. > = > = > = > In both cases, the Button is recalled by using the > same widget definition as > used when the GUI was created (but without setting > the contents of the Entry > box). This seems to have the effect (as expected) > of overwriting the > original definition so that the contents (when the > widget is =91forgotten=92) > are lost. To overcome this: > = > 1. I saved the contents of the Entry widget before > using gridForget for > the first column - in sub forget_CellA_cb; > 2. I retrieved the contents of the Entry widget > after using gridForget > but before using the re-definition for the second > column =96 in sub > recall_CellB_cb. > = > = > = > Both worked. This also showed that the contents of > the second Entry box > were available even though this had been forgotten. > = > = > = > The question is, is there a way of recalling the > =91forgotten=92 widget with its > contents intact without any additional code? > = > = > = > # this tests the forget for a grid widget > = > = > = > use Tk; > = > use strict "vars"; > = > = > = > my ($mw_Main, ); > = > my ($CellA_Entry, $CellB_Entry, $CellC_Entry); > = > my ($CellA_Text, $CellB_Text, $CellC_Text); > = > = > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > = > # > = > # forget call backs > = > # > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > = > = > = > sub forget_CellA_cb() { > = > = > = > $CellA_Text =3D $CellA_Entry->get(); > = > $CellA_Entry->gridForget(); > = > = > = > = > = > } > = > = > = > sub forget_CellB_cb() { > = > = > = > $CellB_Entry->gridForget(); > = > = > = > } > = > = > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > = > # > = > # recall call backs > = > # > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > = > = > = > sub recall_CellA_cb() { > = > = > = > $CellA_Entry =3D $mw_Main->Entry(-width =3D> 6)->grid( > -row =3D> 0, -column =3D> 0); > = > $CellA_Entry->configure(-text =3D> $CellA_Text); > = > } > = > = > = > sub recall_CellB_cb() { > = > = > = > my $CellB_OldText; > = > = > = > $CellB_OldText =3D $CellB_Entry->get(); > = > = > = > $CellB_Entry =3D $mw_Main->Entry(-width =3D> 6)->grid( > -row =3D> 0, -column =3D> 1); > = > $CellB_Entry->configure(-text =3D> $CellB_OldText); > = > } > = > = > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > =3D=3D=3D > = > # > = > # sub gui-set > = > # > = > # this sets up a gui with Entry boxes, forget > buttons and recall buttons > = > = > = > #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > =3D=3D=3D=3D > = > = > = > sub gui_set() { > = > = > = > $mw_Main =3D MainWindow->new; > = > = > = > $CellA_Entry =3D $mw_Main->Entry(-width =3D> 6, -text =3D> > 'AAA')->grid(-row =3D> 0, > -column =3D> 0); > = > $CellB_Entry =3D $mw_Main->Entry(-width =3D> 6, -text =3D> > 'BBB')->grid(-row =3D> 0, > -column =3D> 1); > = > = > = > = > = > $mw_Main->Button(-text =3D> "Forget Entry Box at Top", > -command =3D> > \&forget_CellA_cb)->grid(-row =3D> 1, -column =3D> 0); > = > = > = > $mw_Main->Button(-text =3D> "Forget Entry Box at Top", > -command =3D> > \&forget_CellB_cb)->grid(-row =3D> 1, -column =3D> 1); > = > = > = > = > = > $mw_Main->Button(-text =3D> "Recall Entry Box at Top", > -command =3D> > \&recall_CellA_cb)->grid(-row =3D> 2, -column =3D> 0); > = > = > = > $mw_Main->Button(-text =3D> "Recall Entry Box at > Top",-command =3D> > \&recall_CellB_cb)->grid(-row =3D> 2, -column =3D> 1); > = > = > = > = > = > MainLoop; > = > = > = > } > = > = > = > = > = > ############## in line code > ######################### > = > = > = > gui_set() > = > = > = > = > = > = > = > Best regards > = > = > = > Henry Merryweather > = > = > = > Telephone: +44 (0) 1225 859051 > = > Web: HYPERLINK > "http://www.merryweathersolutions.co.uk"www.merryweathersolutions.co.uk > = > = > = > = > No virus found in this outgoing message. > Checked by AVG Free Edition. = > Version: 7.5.485 / Virus Database: 269.13.15/1002 - > Release Date: 11/09/2007 > 17:46 > = > = > > --++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--+= +**=3D=3D > ptk mailing list > [email protected] > https://mailman.stanford.edu/mailman/listinfo/ptk > = > = _____________________________________________________________________= _______________ Shape Yahoo! in your own image. Join our Network Research Panel today! h= ttp://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=3D7 = --++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--+= +**=3D=3D ptk mailing list [email protected] https://mailman.stanford.edu/mailman/listinfo/ptk