Given above is my code.In that I am validating the name entry not to contain any numeric values.If it does the messageBox displays and goes to the next entry..I need the cursor to be in the same entry if the validation fails. And the other is when I give any character in age enter both messageBoxes i.e dob and ages displays are popping up.

#!usr/bin/perl use warnings; use strict; use Tk; #$\="\n"; my $name; my $age; my $dob; open(my $fh,'+<','details.txt') || die "Can't open the file details.tx +t $!"; #creating a Mainwindow: my $window = MainWindow->new(); my $first_frame = $window -> Frame()->pack(-side => 'top',-ipadx => 10 +,-fill => 'x', -ipady => 1); $first_frame -> Label(-text => 'Fill the details listed below') -> gr +id(-row => 0 ,-column => 2,-rowspan => 1); my $frame = $window -> Frame(-background => 'grey')->pack(-side => 'to +p',-ipadx =>150,-fill => 'x',-ipady => 60); my $name_label=$frame -> Label(-text => 'Name') -> grid(-row => 2, -co +lumn=> 0); my $name_entry=$frame->Entry(-background => 'white',-foreground => 'bl +ack', -textvariable => \$name, -validate => 'focusout',-validatecomma +nd => \&check_name)->grid(-row =>2, -column=>1); my $age_label=$frame -> Label(-text => 'age')-> grid(-row => 4, -colum +n=> 0); my $age_entry = $frame -> Entry(-background => 'white',-foreground => +'black', -textvariable => \$age,-validate => 'focusout',-validatecomm +and => \&check_age) -> grid(-row =>4, -column=>1); my $dob_label=$frame -> Label(-text => 'DOB')-> grid(-row => 6, -colum +n=> 0); my $dob_entry = $frame -> Entry(-background => 'white',-foreground => +'black',-textvariable => \$dob, -validate => 'focusout',-validatecomm +and => \&check_dob) -> grid(-row =>6, -column=>1); $name=$name_entry -> get(); $age = $age_entry -> get(); $dob = $dob_entry -> get(); my $submit = $frame -> Button(-text => 'submit', -command =>sub {&subm +it} ) -> grid( -row =>8, -column=>1); $frame -> Label(-background => 'grey') -> grid(-rowspan=> 6); $frame -> Label(-text => 'After adding all the details click quit to e +xit') -> grid( -row => 16, -column=> 1); $frame -> Label(-background => 'grey') -> grid(-rowspan=> 6); my $quit = $frame -> Button(-text => 'Quit', -command =>sub {exit} ) - +> grid(-row =>25, -column=>1); sub submit { my $line= join(' ',$name,$age,$dob); print $fh $line,"\n"; if(!($?)) { my $button = $frame -> messageBox( -icon => 'info',-message => ' +Details added successfully to file', -type => 'Ok' ); $name_entry->delete('0', 'end'); $age_entry->delete('0', 'end'); $dob_entry->delete('0', 'end'); } } sub check_name { if (($name =~ m/[0-9]/)) { $name_entry -> messageBox( -icon => 'info',-message => 'Name shoul +d not contain numeric values' ,-type => 'Ok'); $name_entry->delete('0', 'end'); } } sub check_age { if (($age=~ m/[a-z]/i)) { $age_entry -> messageBox( -icon => 'error',-message => 'age shoul +d not contain characters' ,-type => 'Ok'); $age_entry->delete('0','end'); } } sub check_dob { if (!($dob=~ m/\d{1,2}[\/|\:]\d{1,2}[\/|\:]\d{4}/)) { $age_entry -> messageBox( -icon => 'error',-message => 'Enter vali +d date' ,-type => 'Ok'); $dob_entry->delete('0', 'end'); } } MainLoop;

In reply to how can i be in the same entry if my validation fails in Tk? by yedukondalu

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.