I found something on the net at http://forums.devshed.com/perl-programming-6/perl-tk-how-to-call-the-event-s-object-entry-630717.html, and also got some confirmation from pg 273 of the book Learning Perl/Tk. Instead of specifying the individual entry boxes, one should use the Tk::Entry class.

use strict; use warnings; use Tk; my ($mw,$EntryBox1,$EntryBox2,$variable1,$variable2,$entry,$variable_p +revious,$variable_current); $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); $mw->bind("Tk::Entry","<FocusIn>",\&save_previous_value); $mw->bind("Tk::Entry","<FocusOut>",\&compare_values); MainLoop; sub save_previous_value { $entry = shift; print "$entry\n"; # i was hoping this would print '$EntryBox1' or '$EntryBox2' # instead it gives me 'Tk::Entry=HASH(0x1bf2f7c)' # or 'Tk::Entry=HASH(0x1bfa9a4)' $variable_previous = $entry->get(); } sub compare_values { $entry = shift; $variable_current = $entry->get(); if ($variable_current ne $variable_previous) { $mw->messageBox(-message => "The value has been changed.",-type => "ok +"); } }

Now the common sub works for all the entry widgets in the main window. I would however like to know the name of the concerned entry widget. Is there some way of finding that out?


In reply to Re^2: perl Tk by jagdish.eashwar
in thread 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.