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

Hello Monks, Happy New Year!! I have a very strange problem. My entry widgets do not take any input. I was previously working on 5.12, so i thought may be enhancing the version may help. But no, today i tried on 5.18.1, same results.. Can anybody please helppppp?

use Tk; use strict; my %info = (); my $mw = MainWindow->new; $mw->title("Data Entry"); my $f = $mw->Frame->pack(-side => 'bottom'); $f->Button(-text => "Exit", -command => sub { exit; })->pack(-side => 'left'); $f->Button(-text => "Save", -command => sub { # do something with %info; })->pack(-side => 'bottom'); foreach (qw/Name Address City State Zip Phone Occupation Company Business_Address Business_Phone/) { $f->Entry(-width => 20, -textvariable => \$info{$_})->pack; } MainLoop;

Replies are listed 'Best First'.
Re: Entry widget does not work in 5.18.1
by zentara (Cardinal) on Jan 10, 2014 at 11:59 UTC
    Just a guess, but I'm betting you have a focus problem. Try clicking the mouse in the entry first, or tabbing around. Try adding $f->focus to force the last entry to have focus. You might want to name your entries better, like $f{'Name'} so you can assign focus order better.

    Some code to show what happens:

    #!/usr/bin/perl use Tk; use strict; use warnings; #changes focus on Return(Enter) key but not Tab my $win = MainWindow->new(); my $foo = $win->Entry->pack; my $bar = $win->Entry->pack; my $baz = $win->Entry->pack; my $boo = $win->Entry->pack; my $baa = $win->Entry->pack; &defineOrder($foo,$baa,$bar,$boo,$baz); sub defineOrder_old { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind('<Key-Return>', [\&focus, $_[$i+1]]); # won't work with Tab $_[$i]->bind('all', '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[$#_]->bind('<Key-Return>', [\&focus, $_[0]]); $_[0]->focus; } sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind( '<Key-Return>', [\&focus, $_[$i+1]]); $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[ $#_ ]->bind('<Key-Return>', [\&focus, $_[0]]); $_[ $#_ ]->bind('<Tab>', [\&focus, $_[0]]); $_[0]->focus; } sub focus { my ($tk, $self) = @_; $self->focus; } MainLoop();

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

      Hi zentara, I tried putting focus just on the last entry and execute. But still other than cursor blinking at last entry widget keyboard input does not reflect in the entry. Thanks for looking. I am at a total loss

        Actually it is all very strange. I am facing this issue in my office. When i switch to perl 5.8.3, the last entry widget in a multiple entry mega widget takes the input, rest all of them dont accept the input even if the cursor blinks in the entry boxes. Now when i switch to Perl 5.18.1, none of the entry boxes takes input, and i realized even Text box is not editable. But at my home where it all works well(on Ubuntu with different versions of Perl) Now i can't understand where the problem lies.

Re: Entry widget does not work in 5.18.1
by Tux (Canon) on Jan 10, 2014 at 11:34 UTC

    Works fine on my box: screenshot


    Enjoy, Have FUN! H.Merijn
Re: Entry widget does not work in 5.18.1
by choroba (Cardinal) on Jan 10, 2014 at 09:49 UTC
    What do you mean by "do not take any input"? Are the entries disabled? Or does not the %info get populated?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I can't see anything in any of the entry box when i type something.
        Have you checked it is not just a colour problem?
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Entry widget does not work in 5.18.1
by kcott (Archbishop) on Jan 12, 2014 at 15:22 UTC

    G'day rjohn1,

    I'm running Perl 5.18.1 and Tk 804.031 on Mac OS X (darwin-thread-multi-2level). I am unable to reproduce your reported problem.

    I ran the code you posted without any changes. I was able to enter text into all the Entry widgets.

    I then modified the Save button as follows:

    $f->Button(-text => "Save", -command => sub { # do something with %info; use Data::Dump; dd \%info; })->pack(-side => 'bottom');

    I then ran the script again and was still able to enter text in all fields. When I hit Save, I got this output which exactly matched what I had entered:

    { Address => 456, Business_Address => "jkl", Business_Phone => "zxc", City => 789, Company => "fgh", Name => 123, Occupation => "asd", Phone => "uio", State => "qwe", Zip => "rty", }

    I always reinstall Tk after upgrading Perl. If you haven't done this, I recommend you do so.

    -- Ken

      Hi Ken, Thanks for looking into it. I know it works. It works for me on my personal Ubuntu machine. But at my workplace (i.e Red Hat Entr Linux Server release 5.8(Tikanga)) , it does not work. Now it is becoming very difficult for me to understand whether the problem lies in my OS, perl/Tk or somewhere else.... Do you know of any definitive place to find the solution for this problem? Thanks RJ

        "Do you know of any definitive place to find the solution for this problem?"

        I don't actually know of a "definitive place" as such. You could try searching the Internet and speaking with your SysAdmins (both obvious and you may already have done this).

        I've front-paged this thread which will give it a little more exposure here.

        -- Ken

Re: Entry widget does not work in 5.18.1 (upgrade Tk version)
by Anonymous Monk on Jan 10, 2014 at 10:11 UTC

      My Tk version is 804.031. This is really crazy. I don't understand what is the problem.

        My Platform is Linux(GNOME)