http://www.perlmonks.org?node_id=1018934


in reply to Re^3: Entry widget with explicit submit button
in thread Entry widget with explicit submit button

okay, but I can't think of a logic because -textvariable of entry widget is changed on the go (as and when user types/changes something). So, how do I revert back to original data on a call from -command of button? (I guess that should have been my exact question, Sorry!)
  • Comment on Re^4: Entry widget with explicit submit button

Replies are listed 'Best First'.
Re^5: Entry widget with explicit submit button
by 7stud (Deacon) on Feb 15, 2013 at 20:15 UTC
    Why are you using a textvariable at all?
    use strict; use warnings; use 5.012; use Tk; my $entry_text; my $mw = MainWindow->new; my $entry = $mw->Entry( -text => 'Enter answer here', )->pack; $entry->focus; $entry->selectionRange(0, 'end'); sub my_validator { my $input = $entry->get(); if ($input eq 'hello') { $entry->delete(0, 'end'); $entry->insert(0, 'Try again!'); $entry->selectionRange(0, 'end'); $entry->icursor(0); } else { say "Thanks for the great input!"; $entry_text = $input; say $entry_text; } } $mw->Button( -text => 'Submit', -command => \&my_validator, )->pack; MainLoop;
Re^5: Entry widget with explicit submit button
by Anonymous Monk on Feb 15, 2013 at 18:25 UTC
    it simple, you keep track of the changes