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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.