Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Checking state entry widget?!

by jerre_111 (Sexton)
on May 03, 2013 at 09:51 UTC ( #1031850=perlquestion: print w/ replies, xml ) Need Help??
jerre_111 has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks

I have a weird thing going on for a few days now, and I can't seem to find the solution.

I have made a program on unix, using the Tk module. I will gave you the basic code you need to compile it and test it on your own.

This program is just 2 pages of a notebook widget. on the first page there are 2 big entry boxes with buttons aside. These I use to browse for files and save files. This is no problem.

but the entry "cell" gives me throubles. this is the smaller entry on the right of the screen.

When you click the button next, which i placed below the screen, I want to continue to page 2. Butt I only want to continue if the entry widget "cell" is not empty!

I have created a subroutine to check the state of the entry widget, but it always says the widget is empty...

So the mssgbox keeps popping up, eventhoug the entry "cell" is not empty.

I have tryd checking with "" as " " to be sure. nothing works.. I have been looking on it for days now.. Hope someone can help me! beneath is my code

use Tk; use Tk::LabFrame; use Tk::Dialog; $mw = MainWindow->new; $mw->geometry("1300x800"); $mw->title("Main window"); $nb = $mw->NoteBook( )->pack(-expand => 1, -fill => 'both'); ####### Create page 1 ########## $p1 = $nb->add('page1', -label => 'Input / Output'); $p1->Button(-text => 'Next', -width => '15', -height => '2', -command +=> \&go_page2,)->place( -x => 1100, -y =>620); $btBrowse = $p1->Button( -text => "Browse", -command => \&browse_file, )->place( -x => 450, -y => 105); $btSave = $p1->Button( -text => "Browse", -command => \&save_file, )->place( -x => 1180, -y => 105); $entrybrowse = $p1->Entry(-width => 60)->place( -x => 20, -y => 110); $entrysave = $p1->Entry(-width => 60)->place( -x => 750, -y => 110); $entry_cell = $p1->Entry(-width => 20)->place( -x => 850, -y => 200); ####### Create page 2 ########## $p2 = $nb->add('page2', -label => 'page2', -state=>'disabled'); MainLoop; sub go_page2 { $name_topcell = $entry_cell->get(); print $name_topcell, "\n"; if ($name_topcell == ""){ print "yes \n"; $mssg_empty = $p1->Dialog(-title => 'Fill in Values', -text => 'Please fill in all the values', -default_button => 'oke', -buttons => [ 'oke'], -bitmap => 'info' )->Show(); } else { $nb->pageconfigure('page2', -state => 'normal'); $nb->raise('page2'); } }

Many Thanks in advance

Comment on Checking state entry widget?!
Download Code
Re: Checking state entry widget?!
by choroba (Abbot) on May 03, 2013 at 10:08 UTC
    You should use eq to compare strings, == can only compare numbers. See perlop for details.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Checking state entry widget?!
by choroba (Abbot) on May 03, 2013 at 10:30 UTC
    Moreover, your code does not use warnings and strict. You are happily using variables in go_page2 that come from the main programme body. Consider a cleaner version of the code:
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::LabFrame; use Tk::Dialog; use Tk::NoteBook; sub go_page2 { warn "<<@_>>"; my ($nb, $entry_cell) = @_; my $name_topcell = $entry_cell->get; print $name_topcell, "\n"; if ($name_topcell eq q()){ print "yes \n"; my $mssg_empty = $nb->Dialog(-title => 'Fill in Value +s', -text => 'Please fill i +n all the values', -default_button => 'oke', -buttons => [ 'oke'], -bitmap => 'info', )->Show; } else { $nb->pageconfigure('page2', -state => 'normal'); $nb->raise('page2'); } } my $mw = MainWindow->new(-title => 'Main window'); $mw->geometry('1300x800'); my $nb = $mw->NoteBook->pack(-expand => 1, -fill => 'both'); ####### Create page 1 ########## my $entry_cell; # To be sent to go_page2. my $p1 = $nb->add('page1', -label => 'Input / Output'); $p1->Button(-text => 'Next', -width => 15, -height => 2, -command => sub { go_page2($nb, $entry_cell) }, )->place( -x => 1100, -y =>620); my $btBrowse = $p1->Button(-text => 'Browse', -command => \&browse_file, )->place( -x => 450, -y => 105); my $btSave = $p1->Button(-text => 'Browse', -command => \&save_file, )->place( -x => 1180, -y => 105); my $entrybrowse = $p1->Entry(-width => 60)->place( -x => 20, -y => 11 +0); my $entrysave = $p1->Entry(-width => 60)->place( -x => 750, -y => 11 +0); $entry_cell = $p1->Entry(-width => 20)->place( -x => 850, -y => 20 +0); ####### Create page 2 ########## my $p2 = $nb->add('page2', -label => 'page2', -state => 'disabled'); MainLoop();

    Note that the user can still fill in the box (which probably should have a label of some sort), activate page 2, return back to page 1, clear the box and return to page 2 by clicking on its tab.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for your advice!! it works now ;).

      Normally I put a label next to the entry widget. this is just a quick copy paste from the original program just so you could run and compile the test program to understand my problem.

      Thank you very much!

Re: Checking state entry widget?!
by Anonymous Monk on May 03, 2013 at 20:55 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1031850]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-04-17 11:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (445 votes), past polls