Entry->bind() problems 
Author Message
 Entry->bind() problems

I am having some problems.  I am trying to use an Entry for numeric
input
and only want [0-9\-.] inserted into the entry.  I also would like to
bind
'q' to a custom function.  I tried the following...

#!/usr/bin/perl
use strict;
use Tk;

my $MW = MainWindow->new;
$MW->title('test');
$MW->geometry('+3+3');
my $frm=$MW->Frame();
$frm->pack(-side => 'top');

my $entry=$frm->Entry();
$entry->pack(-side => 'top');
$entry->bind('<KeyPress>' => \&NoOp);
$entry->bind('<KeyPress-q>' => \&Func);

sub Func {
    print "do it!\n";

Quote:
}

sub NoOp { ; }
MainLoop;

I was expecting this code to execute Func whenever the 'q' key is
pressed without
inserting the character into the entry.  Well... it printed "do it!\n"
and
inserted.  

What am I doing wrong?

Paul Hansen



Tue, 07 Dec 1999 03:00:00 GMT  
 Entry->bind() problems

Quote:

> I am having some problems.  I am trying to use an Entry for numeric
> input and only want [0-9\-.] inserted into the entry.  I also would
> like to bind 'q' to a custom function.  I tried the following...

[snip]

Quote:
> $entry->bind('<KeyPress-q>' => \&Func);

> sub Func {
>     print "do it!\n";
> }

[snip]

Quote:
> I was expecting this code to execute Func whenever the 'q' key is
> pressed without inserting the character into the entry.  Well... it
> printed "do it!\n" and inserted.

Tk executes the bindings sequentially for the Tk::Entry class, $entry,
the toplevel `.' and finally for `all' widgets.  See bind() and
bindtags() in the manual, and have a look at this program.

#!/usr/bin/perl -w

use strict;
use Tk;

my $MW = new MainWindow;
my $e = $MW->Entry()->pack();

$e->bindtags([$e, ref($e), $e->toplevel(), 'all']);
$e->bind('<KeyPress-q>' => sub { print "Perl.  Just do it.\n"; Tk->break; });

MainLoop();

--

       "Our mail program accidentally deleted our remove list."
                                                 - Real quote from UCE



Thu, 09 Dec 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. binding <Return> on an Entry

2. Entry binding problem

3. $widget->bind returns one binding only

4. entry->configure( -width => 0)

5. Binding event to entry widget

6. Mouse Click Bind for an Entry Widget

7. how to bind return key to entry widget

8. bind a hlist entry

9. Can't bind Shift Tab to an Entry

10. binding a comand on an entry widget (again a newbie question)

11. Bind, Entry widgets and the MS Windows Manager

12. Bind & Entry widgets

 

 
Powered by phpBB® Forum Software