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

I have a very large Tk GUI (7000 lines long), and in general, it works very well indeed.

However, occasionally, I get a load of errors reported to the invocation shell:

Tk::Error: Failed to AUTOLOAD 'Tk::Widget::EnterFocus' at /eda/dm/home/mili/scripts/perl/run.tk.pl line 264

(where line 264 is the invocation of MainLoop()

This error occurs randomly, and after many features of my GUI have been working just fine.

One example of when this error message occurs is simply when the mouse moves into the GUI (I have focus-follows-mouse ... so simply moving the mouse into the GUI window causes this EnterFocus error.)

That is, the program is working fine for many days/weeks, and then all of sudden, for no apparent reason, when the mouse moves into that window, I get the EnterFocus error.

Any thoughts on what might be causing this EnterFocus issue?

Thank you for any thoughts you have.

  • Comment on Tk::Error: Failed to AUTOLOAD `TK::Widget::EnterFocus'

Replies are listed 'Best First'.
Re: Tk::Error: Failed to AUTOLOAD `TK::Widget::EnterFocus'
by choroba (Cardinal) on May 15, 2023 at 15:03 UTC
    Interestingly, there's no such a thing as Tk::Widget::EnterFocus.

    The string EnterFocus is mentioned several times in the Tk source, though:

    $ ack EnterFocus ~/perl5/lib/perl5/ /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/Tk.pm 703:sub EnterFocus 720: $widget->bind('all','<Enter>','EnterFocus'); /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/Tk/Menu.pm 999: # $menu->bind('<Enter>','EnterFocus'); /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Tk/EnterF +ocus.al 6:#line 693 "blib/lib/Tk.pm (autosplit into blib/lib/auto/Tk/EnterFocu +s.al)" 17:sub EnterFocus 26:# end of Tk::EnterFocus /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Tk/autosp +lit.ix 21:sub EnterFocus /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Tk/.packl +ist 483:/home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Tk/En +terFocus.al /home/choroba/perl5/lib/perl5/x86_64-linux-thread-multi/auto/Tk/focusF +ollowsMouse.al 10: $widget->bind('all','<Enter>','EnterFocus');

    What version of Perl and Tk are you running?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Hello choroba,

      I have the file EnterFocus.al under perl5.26.64bit\perl\site\lib\auto\Tk and it contains:

      # NOTE: Derived from blib\lib\Tk.pm. # Changes made here will be lost when autosplit is run again. # See AutoSplit.pm. package Tk; #line 693 "blib\lib\Tk.pm (autosplit into blib\lib\auto\Tk\EnterFocus. +al)" # focusFollowsMouse # # If this procedure is invoked, Tk will enter "focus-follows-mouse" # mode, where the focus is always on whatever window contains the # mouse. If this procedure isn't invoked, then the user typically # has to click on a window to give it the focus. # # Arguments: # None. sub EnterFocus { my $w = shift; return unless $w; my $Ev = $w->XEvent; my $d = $Ev->d; $w->Tk::focus() if ($d eq 'NotifyAncestor' || $d eq 'NotifyNonlinear +' || $d eq 'NotifyInferior'); } # end of Tk::EnterFocus 1;

      I also see this comment in Tk.pm source

      PS $widget->focusFollowsMouse is described here

      PPS perhaps I misread/misunderstood your answer :)

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Thank you for your reply.

      I'm using PERL 5.16.3

      And Tk version 804.03

        Your Tk version is more than 11 years old: Changes, and your Perl is 10 years old: perlhist.

        It seems like some kind of namespace problem, the program tries to autoload EnterFocus and guesses the namespace incorrectly.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Tk::Error: Failed to AUTOLOAD `TK::Widget::EnterFocus'
by hippo (Archbishop) on May 15, 2023 at 14:53 UTC
    That is, the program is working fine for many days/weeks, and then all of sudden, for no apparent reason, when the mouse moves into that window, I get the EnterFocus error.

    If by that you mean that one single instance of the program is running for weeks on end then it could perhaps be that some resource is being slowly exhausted (open files, RAM, etc.). It would be a little odd if it is only one specific action causing this error to manifest but then we haven't see your code so anything's possible.


    🦛