I want to monitor if the value of an entry box has been changed. So on the FocusIn event, I am storing the present value in $variable1_previous by binding a sub, and on the FocusOut event, I am comparing the values of $variable1 and $variable1_previous again through a bound sub.
use strict; use warnings; use Tk; my ($mw,$EntryBox1,$EntryBox2,$variable1,$variable1_previous,$variable +2); $mw = MainWindow->new; $EntryBox1 = $mw->Entry(-textvariable => \$variable1, ) ->place(-relx => 0.06, -rely => 0.03); $EntryBox2 = $mw->Entry(-textvariable => \$variable2, ) ->place(-relx => 0.06, -rely => 0.20); $EntryBox1->bind("<FocusIn>",\&save_previous_value); $EntryBox1->bind("<FocusOut>",\&compare_values); MainLoop; sub save_previous_value { $variable1_previous = $variable1; } sub compare_values { if ($variable1 ne $variable1_previous) { $mw->messageBox(-message => "The value has been changed.",-type => "ok +"); } }
Is this the way to do it? When the number of entry boxes to be so monitored are large, will it be necessary to write a sub for each entry box? Is it possible to write a common sub which I can bind to all of them? Can the concerned variables be referred to in a generic fashion rather than be named each time? Like something which refers to the variable of the entry box that was the subject of the FocusIn or FocusOut event?
In reply to perl Tk by jagdish.eashwar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |