Real Perl has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I sure would appreciate your wisdom on this one:
I have some entry boxes (only give you one here).

$case_numbertf = $page1 -> Entry(-textvariable => \$case_number) ->pla +ce(-x=> 380, -y=> 30);

And some scrollable text areas:

$agency_infotf = $page1 -> Scrolled('Text', -scrollbars=> 'e', -width= +> 25, -height=>1)->place(-x=> 15, -y=> 85);
Then, I check to see if my user has typed in those so I can let him/her know what is not filled out.
So, to check the entry box:
if ($case_number eq ""){ $dialog = $mw-> Dialog( -title => 'Alert', -text => "Please Complete ALL the Fields on the First Tab", -buttons => [ qw(OK) ]) ->Show();

And I check the scrollable text area:

$agency_info = $agency_infotf->get('1.0','end'); if ($agency_info eq ""){ $dialog = $mw-> Dialog( -title => 'Alert', -text => "Please Complete ALL the Fields on the First Tab", -buttons => [ qw(OK) ]) ->Show();
Checking the entry box works great, but it looks like I need to use something else beside eq "" to determine if the text area is empty.

Thank you in advance for your time.

Claire

Replies are listed 'Best First'.
Re: Text Widget empty string
by pg (Canon) on Jul 29, 2005 at 04:55 UTC

    There is always a newline there in the text widget, that is how it is initialized and you cannot even delete it. If you don't type anything, the length of the content will be 1; if you type something, the length is no longer 1.

    use Tk; use Tk::Dialog; use strict; use warnings; my $page1 = MainWindow->new(); my $agency_infotf = $page1 -> Scrolled('Text', -scrollbars=> 'e', -wid +th=> 25, -height=>1)->pack; my $button = $page1->Button(-text => "Click", -command => \&verify)->p +ack(); MainLoop; sub verify { my $agency_info = $agency_infotf->get('1.0', 'end'); if (length($agency_info) == 1){ my$dialog = $page1-> Dialog( -title => 'Alert', -text => "Please Complete ALL the Fields on the First Tab" +, -buttons => [ qw(OK) ]) ->Show(); } }
      Thank you so much!
Re: Text Widget empty string
by GrandFather (Saint) on Jul 29, 2005 at 04:09 UTC

    Why $agency_infotf->get('1.0','end') rather than $agency_infotf->get(0,'end')?


    Perl is Huffman encoded by design.

      He actually did that part right. '1.0' is a valid index, but '0' is not.