I want to validate the fields

The only widget I know of in Tk, that supports validation, is the Tk::Entry. Additionally, your program dosn't run as shown, it crashes because of the way you specify your -command callbacks. When you specify

-command => \&sub_opt,
the command is executed immediately when the Optionmenu is being created, and it will fail with an error. You want to wrap the command in or a sub{} like this:
-command => sub { \&sub_opt },
When you make callbacks, you set them up to be something that is "called later" not immediately.

Here's a bit more of an explanation:

#!/usr/bin/perl #for example the following is wrong my $row = 0; my $column = 0; for (my $i = 9; $i >= 0; $i--) { $button{$i} = $mw->Button(-text => "$i", -width => '3', -height => '1', -command => &numpress($i)) ->grid(-row => $row, -column => $column); $column++; if($column > 2){$column = 0; $row++;} } MainLoop; ####################################################### # Now the problem is here: -command => &numpress($i)) # The thing being assigned to the "-command" attribute needs # to be an anonymous subroutine, a reference to a named subroutine, # or else a reference to an array whose elements are: # named_subroutine_ref, arg1(, arg2 ...) -- in other words, # either of the following would be the right way to do what you want: -command => sub { numpress( $i ) } # or -command => [ \&numpress, $i ] #The way you had it written, your subroutine is actually being called #when the Button is being created, and Perl/Tk is trying to use the #return value of the sub as the value for "-command" -- not good.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: optionmenu configure problem in perl tk by zentara
in thread optionmenu configure problem in perl tk by vr786

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.