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

I used the following code to display a message box.
use strict; use warnings; use Tk; my $mw=new MainWindow; $mw->withdraw(); $mw->messageBox(-icon => 'info', -message =>"Hai", -title => "Testing" +, -type => 'ok');

The above code shows the message box. My question is as follows

If I press the "enter" button(which is near to alphabets and symbols) it consider the input as ok and the message box got closed.

But when I press the "enter" button(which is near to the numlock(Keypad)) it is not considered as "ok" and the message box window remains on the screen.

Now what should I do to make it work?

Replies are listed 'Best First'.
Re: TK:Message box
by zentara (Cardinal) on Apr 06, 2009 at 11:59 UTC
    Run this program, observe how it works, then bind the correct key symbol into your messagebox code.
    #!/usr/bin/perl use Tk; $mw = MainWindow->new; $mw->bind("<Key>", [ sub { print "Key Press: $_[1] \n" } , Ev('K') ] + ); $mw->bind("<KeyRelease>", [ sub { print "Key Release: $_[1] \n" } , Ev +('K') ] ); MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: TK:Message box
by jethro (Monsignor) on Apr 06, 2009 at 12:08 UTC

    If you start wish (a tk shell) with the following command, you can see the KeySym name that Tk receives. In this case the keypad return key has the keysym 'KP_Enter' while the normal return key has the keysym 'Return'

    wish % bind . <KeyPress> {puts %K} KP_Enter Return

    This can be used as in the question "10.5. How do I bind keyboard keys?" of the perl/tk FAQ http://www.faqs.org/faqs/perl-faq/ptk-faq/part2/

    PS: This information and more can be found on the web by searching for 'tk keyboard mapping' and 'perl/tk key bindings'.