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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |