Beginner's question on clearing Entry/Text boxes
Author |
Message |
Chri #1 / 10
|
 Beginner's question on clearing Entry/Text boxes
I have several Entry and one Text box on a form/widget. After I click my Write Data button, I would like to clear all of the fields. They are laid out as such: Label: Entry Label: Text Then a for loop for 20 more Labels: Entry's my $row; for ($row = 0; $row < 20; $row++) { $entryF->Label( -width => 10, -anchor => 'w', -text => "Step " . ($row + 1), )->grid( $entryF->Entry( -width => 65, -textvariable => \$value[$row] ), -sticky => 'w' ); Quote: }
After I enter the data and click my Button, it goes and writes the data to a text file. Now I want it to clear all of the above out. Any help would be appreciated, even if it is to point me to the correct docs/examples. TIA! -- Chris Anderson
|
Wed, 21 Jul 2004 00:38:33 GMT |
|
 |
Chri #2 / 10
|
 Beginner's question on clearing Entry/Text boxes
Ok, I go the Text cleared.. Easy enough $text = $summaryT->delete("1.0", "end"); I am still looking for how to clear out an Entry box... TIA
Quote: > I have several Entry and one Text box on a form/widget. > After I click my Write Data button, I would like to clear all of the fields. > They are laid out as such: > Label: Entry > Label: Text > Then a for loop for 20 more Labels: Entry's > my $row; > for ($row = 0; $row < 20; $row++) { > $entryF->Label( > -width => 10, > -anchor => 'w', > -text => "Step " . ($row + 1), > )->grid( > $entryF->Entry( > -width => 65, > -textvariable => \$value[$row] > ), > -sticky => 'w' > ); > } > After I enter the data and click my Button, it goes and writes the data to a > text file. > Now I want it to clear all of the above out. > Any help would be appreciated, even if it is to point me to the correct > docs/examples. > TIA! > -- > Chris Anderson
|
Wed, 21 Jul 2004 04:46:22 GMT |
|
 |
smackd #3 / 10
|
 Beginner's question on clearing Entry/Text boxes
To clear an Entry widget: $w->delete->(0, 'end'); To clear a Text widget: $w->delete->('1.0', 'end'); Quote:
> I have several Entry and one Text box on a form/widget. > After I click my Write Data button, I would like to clear all of the fields. > They are laid out as such: > Label: Entry > Label: Text > Then a for loop for 20 more Labels: Entry's > my $row; > for ($row = 0; $row < 20; $row++) { > $entryF->Label( > -width => 10, > -anchor => 'w', > -text => "Step " . ($row + 1), > )->grid( > $entryF->Entry( > -width => 65, > -textvariable => \$value[$row] > ), > -sticky => 'w' > ); > } > After I enter the data and click my Button, it goes and writes the data to a > text file. > Now I want it to clear all of the above out. > Any help would be appreciated, even if it is to point me to the correct > docs/examples. > TIA!
|
Wed, 21 Jul 2004 07:06:02 GMT |
|
 |
Chuck Lawhor #4 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> Ok, > I go the Text cleared.. > Easy enough > $text = $summaryT->delete("1.0", "end"); > I am still looking for how to clear out an Entry box... > TIA
If you use the -textvariable option in the Entry widget, you can clear the widget using the following, which is what I do: $Variable = ''; $MainWindow->update; This will clear both the variable's value and the entry widget. --Chuck
|
Wed, 21 Jul 2004 08:35:57 GMT |
|
 |
Chri #5 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> > Ok, > > I go the Text cleared.. > > Easy enough > > $text = $summaryT->delete("1.0", "end"); > > I am still looking for how to clear out an Entry box... > > TIA > If you use the -textvariable option in the Entry widget, you can clear the > widget using the following, which is what I do: > $Variable = ''; > $MainWindow->update; > This will clear both the variable's value and the entry widget. > --Chuck
|
Fri, 23 Jul 2004 22:25:36 GMT |
|
 |
Chri #6 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> > Ok, > > I go the Text cleared.. > > Easy enough > > $text = $summaryT->delete("1.0", "end"); > > I am still looking for how to clear out an Entry box... > > TIA > If you use the -textvariable option in the Entry widget, you can clear the > widget using the following, which is what I do: > $Variable = ''; > $MainWindow->update; > This will clear both the variable's value and the entry widget. > --Chuck
Ok, It is not working, and I am sure it is because of how I am creating and using the Entry boxes.. Here is how I have them being created (Most of the code is from help from this group): #*********************************************************** #* #* Add 20 Steps - We could add more, if needed.... #* #*********************************************************** my $row; for ($row = 0; $row < 20; $row++) { $entryF->Label( -width => 10, -anchor => 'w', -text => "Step " . ($row + 1), )->grid( $entryF->Entry( -width => 65, -textvariable => \$value[$row] ), -sticky => 'w' ); Quote: }
Later, after I click a "Write Data" button, I get the info as such: #*********************************************************** #* #* Extract only those values that have a value other #* than null or "" #* #***********************************************************
for (my $i = 0; $i < 20; $i++) { my $value = $valAR->[$i]; if (defined($value) && $value ne "") {
$value = ''; # This was added per your comments... $summaryT->update; # $summaryT is what I use for the main window, # see the below deletes that work... } } $wtext = $summaryT->Entry->delete("1.0", "end"); $text = $summaryT->delete("1.0", "end"); my $step = 1; #*********************************************************** #* #* Loop through, and print the steps, if there is valid #* data #* #***********************************************************
my $text;
$text = sprintf("$spacing%2d) ", $step++); } else { $text = sprintf("$spacing%d) ", $step++); } $text .= $goodValue[$i]; print DUMPFILE "$text \n"; print "$text\n"; } Any help would be grateful.. All help so far is muchly appreciated! :) Chris
|
Fri, 23 Jul 2004 22:26:46 GMT |
|
 |
Chuck Lawhor #7 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> > > Ok, > > > I go the Text cleared.. > > > Easy enough > > > $text = $summaryT->delete("1.0", "end"); > > > I am still looking for how to clear out an Entry box... > > > TIA > > If you use the -textvariable option in the Entry widget, you can clear the > > widget using the following, which is what I do: > > $Variable = ''; > > $MainWindow->update; > > This will clear both the variable's value and the entry widget. > > --Chuck > Ok, > It is not working, and I am sure it is because of how I am creating and > using the Entry boxes.. > Here is how I have them being created (Most of the code is from help from > this group): > #*********************************************************** > #* > #* Add 20 Steps - We could add more, if needed.... > #* > #*********************************************************** > my $row; > for ($row = 0; $row < 20; $row++) { > $entryF->Label( > -width => 10, > -anchor => 'w', > -text => "Step " . ($row + 1), > )->grid( > $entryF->Entry( > -width => 65, > -textvariable => \$value[$row] > ), > -sticky => 'w' > ); > } > Later, after I click a "Write Data" button, I get the info as such: > #*********************************************************** > #* > #* Extract only those values that have a value other > #* than null or "" > #* > #***********************************************************
> for (my $i = 0; $i < 20; $i++) { > my $value = $valAR->[$i]; > if (defined($value) && $value ne "") {
> $value = ''; # This was added per your > comments... > $summaryT->update; # $summaryT is what I use for the main > window, > # see the below deletes > that work... > } > } > $wtext = $summaryT->Entry->delete("1.0", "end"); > $text = $summaryT->delete("1.0", "end"); > my $step = 1; > #*********************************************************** > #* > #* Loop through, and print the steps, if there is valid > #* data > #* > #***********************************************************
> my $text;
> $text = sprintf("$spacing%2d) ", $step++); > } else { > $text = sprintf("$spacing%d) ", $step++); > } > $text .= $goodValue[$i]; > print DUMPFILE "$text \n"; > print "$text\n"; > } > Any help would be grateful.. > All help so far is muchly appreciated! :) > Chris
You added $value=''; per my recommendation. $value isn't the variable you used
different. You must clear the array variable $value[some number between 0 and (number of array elements -1)] in order to have the Entry widget reflect the change. Hope this helps, --Chuck
|
Sun, 25 Jul 2004 13:05:42 GMT |
|
 |
Chri #8 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> > > > Ok, > > > > I go the Text cleared.. > > > > Easy enough > > > > $text = $summaryT->delete("1.0", "end"); > > > > I am still looking for how to clear out an Entry box... > > > > TIA > > > If you use the -textvariable option in the Entry widget, you can clear the > > > widget using the following, which is what I do: > > > $Variable = ''; > > > $MainWindow->update; > > > This will clear both the variable's value and the entry widget. > > > --Chuck > > Ok, > > It is not working, and I am sure it is because of how I am creating and > > using the Entry boxes.. > > Here is how I have them being created (Most of the code is from help from > > this group): > > #*********************************************************** > > #* > > #* Add 20 Steps - We could add more, if needed.... > > #* > > #*********************************************************** > > my $row; > > for ($row = 0; $row < 20; $row++) { > > $entryF->Label( > > -width => 10, > > -anchor => 'w', > > -text => "Step " . ($row + 1), > > )->grid( > > $entryF->Entry( > > -width => 65, > > -textvariable => \$value[$row] > > ), > > -sticky => 'w' > > ); > > } > > Later, after I click a "Write Data" button, I get the info as such: > > #*********************************************************** > > #* > > #* Extract only those values that have a value other > > #* than null or "" > > #* > > #***********************************************************
> > for (my $i = 0; $i < 20; $i++) { > > my $value = $valAR->[$i]; > > if (defined($value) && $value ne "") {
> > $value = ''; # This was added per your > > comments... > > $summaryT->update; # $summaryT is what I use for the main > > window, > > # see the below deletes > > that work... > > } > > } > > $wtext = $summaryT->Entry->delete("1.0", "end"); > > $text = $summaryT->delete("1.0", "end"); > > my $step = 1; > > #*********************************************************** > > #* > > #* Loop through, and print the steps, if there is valid > > #* data > > #* > > #***********************************************************
> > my $text;
> > $text = sprintf("$spacing%2d) ", $step++); > > } else { > > $text = sprintf("$spacing%d) ", $step++); > > } > > $text .= $goodValue[$i]; > > print DUMPFILE "$text \n"; > > print "$text\n"; > > } > > Any help would be grateful.. > > All help so far is muchly appreciated! :) > > Chris > The variable you use in the Entry widget is $value[$row]. I don't see the array
> You added $value=''; per my recommendation. $value isn't the variable you used
> different. You must clear the array variable $value[some number between 0 and > (number of array elements -1)] in order to have the Entry widget reflect the > change. > Hope this helps, > --Chuck
COOL!!! Added [$i] to the $value='' Thus, it became: $value[$i]=''; and this fixed this!!!! MUCHO GRACIAS!!!! :) Now, the last question.. I have a scroll bar: #*********************************************************** #* #* Make the Window Scrollable. #* #*********************************************************** my $pane = $stepF->Scrolled("Pane", -scrollbars => 'osoe', -sticky => 'w', -height => 150, )->pack(%packinfo, -fill => 'x', -padx => 4, -pady => 4); my $entryF = $pane->Frame->pack(%packinfo); And when I tab down below the scroll, I would like it to auto-scroll. Is this a function of scroll, or do I have to manually code it? If I have to manually code it, where would be a good place, with examples, on how to do this??? :)
|
Mon, 26 Jul 2004 04:38:06 GMT |
|
 |
Rob Seeg #9 / 10
|
 Beginner's question on clearing Entry/Text boxes
Quote:
> And when I tab down below the scroll, I would like it to auto-scroll. Is > this a function of scroll, > or do I have to manually code it?
As you look through the docs (and/or buy Steve and Nancy's book) you will notice most of the widgets that can be scrolled have a method called "see". The Pane widget supports this method (as documented). This is the easiest way of getting what you're looking for. Try restructuring the code that creates your Entries to something like this: my $entry = $entryF->Entry( -width => 35, -textvariable => \$value[$row] ); my $label = $entryF->Label( -width => 3, -anchor => 'w', -text => ($row + 1), )->grid($entry, -sticky => 'w' ); $entry->bind('<FocusIn>', [\&showEntry, $pane, $label]); Notice that I've pulled the Entry widget out of the grid so that I could get an easy reference to it (you could have gotten it through the grid manager also). I've done this so that I can bind a callback that is called everytime the entry receives focus (ie. you tab to it) Now, at the end of your code add the showEntry subroutine. Something like this: sub showEntry {
$pane->see($l, -anchor => 's'); Quote: }
This isn't much code, and you could have done it just as easily inline, but personally I find it slightly easier maintenance-wise to define a sub. Now, everytime an entry is tabbed to, it will ensure that the label before the entry is visible. I used the label instead of the Entry because I wanted the beginning of the Entry to be made visible, if your windows was resized smaller. If you had used $e instead of $l, then there would be chance that you wouldn't see the number next to each entry as you scrolled. Rob
|
Mon, 26 Jul 2004 15:50:16 GMT |
|
 |
Chri #10 / 10
|
 Beginner's question on clearing Entry/Text boxes
GREAT! Many thanks, to ALL! Now if Barnes and Nobles or Waldenbooks would get the Mastering P/Tk!!!!! :)
Quote: > > And when I tab down below the scroll, I would like it to auto-scroll. Is > > this a function of scroll, > > or do I have to manually code it? > As you look through the docs (and/or buy Steve and Nancy's book) > you will notice most of the widgets that can be scrolled have a > method called "see". The Pane widget supports this method (as > documented). This is the easiest way of getting what > you're looking for. > Try restructuring the code that creates your Entries to > something like this: > my $entry = $entryF->Entry( > -width => 35, > -textvariable => \$value[$row] > ); > my $label = $entryF->Label( > -width => 3, > -anchor => 'w', > -text => ($row + 1), > )->grid($entry, > -sticky => 'w' > ); > $entry->bind('<FocusIn>', [\&showEntry, $pane, $label]); > Notice that I've pulled the Entry widget out of the > grid so that I could get an easy reference to it (you > could have gotten it through the grid manager also). > I've done this so that I can bind a callback that is > called everytime the entry receives focus (ie. you tab > to it) > Now, at the end of your code add the showEntry subroutine. > Something like this: > sub showEntry {
> $pane->see($l, -anchor => 's'); > } > This isn't much code, and you could have done it just > as easily inline, but personally I find it slightly > easier maintenance-wise to define a sub. Now, everytime > an entry is tabbed to, it will ensure that the label > before the entry is visible. I used the label instead > of the Entry because I wanted the beginning of the > Entry to be made visible, if your windows was resized > smaller. If you had used $e instead of $l, then there > would be chance that you wouldn't see the number next > to each entry as you scrolled. > Rob
|
Mon, 26 Jul 2004 22:34:14 GMT |
|
|
|