Problems removing a binding 
Author Message
 Problems removing a binding

Hi all,

I want to remove a binding from an Entry widget, but it doesn't appear
to be working.  Now, the Walsh book says, "To remove a binding for a
specific sequence, send an empty string for the callback" (p. 271).

So here's the quandry:

I've created a bind using "<Key>" for an entry widget.  That *is* what
I want, except for the 'Control' key.  So I tried:

$entry->bind("<Control-Key>", " ");

I tried just '<Control>' as well as passing "" as string.  No
difference.  That doesn't seem to remove the binding.  Is it not
possible to remove bindings on the modifiers themselves?

Any and all help is appreciated.  Thanks in advance.

Dan

### Sample Code ###

use Tk;

my $mw = MainWindow->new;
my $entry = $mw->Entry->pack;

$entry->bind('<Key>', sub{ print "\nWassup?" }
$entry->bind('<Control-Key>', " "); # No effect

MainLoop;

### End Sample Code ###
--
In the immortal words of Socrates, "I drank what?"

Sent via Deja.com
http://www.*-*-*.com/



Sun, 22 Jun 2003 22:18:34 GMT  
 Problems removing a binding
The following code works for me:

### Sample Code ###

use Tk;

my $mw = MainWindow->new;
my $entry = $mw->Entry->pack;

$entry->bind('<Key>', sub{ print "\nWassup?" });

$entry->bind('<Control-Key>', sub{ Tk->break; }); # Skips other processing for key events

MainLoop;

### End Sample Code ###

I think there is some discussion of Tk->break in the Tk::bind
documentation. Basically, the Tk->break stops processing of other
matching key events.

-John

Quote:

> Hi all,

> I want to remove a binding from an Entry widget, but it doesn't appear
> to be working.  Now, the Walsh book says, "To remove a binding for a
> specific sequence, send an empty string for the callback" (p. 271).

> So here's the quandry:

> I've created a bind using "<Key>" for an entry widget.  That *is* what
> I want, except for the 'Control' key.  So I tried:

> $entry->bind("<Control-Key>", " ");

> I tried just '<Control>' as well as passing "" as string.  No
> difference.  That doesn't seem to remove the binding.  Is it not
> possible to remove bindings on the modifiers themselves?

> Any and all help is appreciated.  Thanks in advance.

> Dan

> ### Sample Code ###

> use Tk;

> my $mw = MainWindow->new;
> my $entry = $mw->Entry->pack;

> $entry->bind('<Key>', sub{ print "\nWassup?" }
> $entry->bind('<Control-Key>', " "); # No effect

> MainLoop;

> ### End Sample Code ###
> --
> In the immortal words of Socrates, "I drank what?"

> Sent via Deja.com
> http://www.deja.com/



Mon, 23 Jun 2003 21:15:54 GMT  
 Problems removing a binding
John,

I read the docs and tried it. No luck.  This is on perl 5.6, Tk800.022
on Slackware 7.1.

Strange.  What version of Perl & Perl/Tk are you using?  What OS?  If
it works for you and not for me, that tells me there's some sort of OS
specific problem, or a problem with the version of Perl - Perl/Tk that
I'm using.

Any ideas?

Regards,

Dan



Quote:
> The following code works for me:

> ### Sample Code ###

> use Tk;

> my $mw = MainWindow->new;
> my $entry = $mw->Entry->pack;

> $entry->bind('<Key>', sub{ print "\nWassup?" });

> $entry->bind('<Control-Key>', sub{ Tk->break; }); # Skips other

processing for key events

Quote:

> MainLoop;

> ### End Sample Code ###

> I think there is some discussion of Tk->break in the Tk::bind
> documentation. Basically, the Tk->break stops processing of other
> matching key events.

> -John


> > Hi all,

> > I want to remove a binding from an Entry widget, but it doesn't
appear
> > to be working.  Now, the Walsh book says, "To remove a binding for a
> > specific sequence, send an empty string for the callback" (p. 271).

> > So here's the quandry:

> > I've created a bind using "<Key>" for an entry widget.  That *is*
what
> > I want, except for the 'Control' key.  So I tried:

> > $entry->bind("<Control-Key>", " ");

> > I tried just '<Control>' as well as passing "" as string.  No
> > difference.  That doesn't seem to remove the binding.  Is it not
> > possible to remove bindings on the modifiers themselves?

> > Any and all help is appreciated.  Thanks in advance.

> > Dan

> > ### Sample Code ###

> > use Tk;

> > my $mw = MainWindow->new;
> > my $entry = $mw->Entry->pack;

> > $entry->bind('<Key>', sub{ print "\nWassup?" }
> > $entry->bind('<Control-Key>', " "); # No effect

> > MainLoop;

> > ### End Sample Code ###
> > --
> > In the immortal words of Socrates, "I drank what?"

> > Sent via Deja.com
> > http://www.deja.com/

--
In the immortal words of Socrates, "I drank what?"

Sent via Deja.com
http://www.deja.com/



Mon, 23 Jun 2003 22:36:59 GMT  
 Problems removing a binding


Quote:
> Hi all,

> I want to remove a binding from an Entry widget, but it doesn't appear
> to be working.  Now, the Walsh book says, "To remove a binding for a
> specific sequence, send an empty string for the callback" (p. 271).

Here is one way..

Note you don't even need the Tk::NoOp, just a sub{}..

######################################
use Tk;
use strict;

my $entry = tkinit->Entry->pack;
$entry->bind('<Any-KeyPress>', sub{ print "\nWassup?" });

$entry->bind('<Control-KeyPress>', sub {Tk::NoOp;});

MainLoop;
######################################

Sent via Deja.com
http://www.deja.com/



Tue, 24 Jun 2003 02:01:20 GMT  
 Problems removing a binding
Tried it - still doesn't work.  Tried both with and without Tk::NoOp.
Still prints "Wassup?" when I press the Control key in both Slackware
7.1 and Windows NT.

Any other ideas?  Is it hopeless?

Regards,

Dan


Quote:



> > Hi all,

> > I want to remove a binding from an Entry widget, but it doesn't
appear
> > to be working.  Now, the Walsh book says, "To remove a binding for a
> > specific sequence, send an empty string for the callback" (p. 271).

> Here is one way..

> Note you don't even need the Tk::NoOp, just a sub{}..

> ######################################
> use Tk;
> use strict;

> my $entry = tkinit->Entry->pack;
> $entry->bind('<Any-KeyPress>', sub{ print "\nWassup?" });

> $entry->bind('<Control-KeyPress>', sub {Tk::NoOp;});

> MainLoop;
> ######################################

> Sent via Deja.com
> http://www.deja.com/

--
In the immortal words of Socrates, "I drank what?"

Sent via Deja.com
http://www.deja.com/



Tue, 24 Jun 2003 02:59:14 GMT  
 Problems removing a binding


Quote:
> Tried it - still doesn't work.  Tried both with and without Tk::NoOp.
> Still prints "Wassup?" when I press the Control key in both Slackware
> 7.1 and Windows NT.

> Any other ideas?  Is it hopeless?

It sounds as if you want to bind every key BUT the control key (all by
itself). Is that correct?

If so...just find out the keysym for the control key and bind to the
NoOp.

$entry->bind('<Control_L>',sub{Tk::NoOp});

works for me.

Jack

Sent via Deja.com
http://www.deja.com/



Tue, 24 Jun 2003 11:26:53 GMT  
 Problems removing a binding
Thanks!  That did the trick nicely.  I'll have to look up info on
Tk::NoOp, because I never heard of it until this week.

Strangely, the chapter on Tk seems to have (literally) disappeared from
my ActiveState documentation.  Hmmm....

Dan


Quote:



> > Tried it - still doesn't work.  Tried both with and without
Tk::NoOp.
> > Still prints "Wassup?" when I press the Control key in both
Slackware
> > 7.1 and Windows NT.

> > Any other ideas?  Is it hopeless?

> It sounds as if you want to bind every key BUT the control key (all by
> itself). Is that correct?

> If so...just find out the keysym for the control key and bind to the
> NoOp.

> $entry->bind('<Control_L>',sub{Tk::NoOp});

> works for me.

> Jack

> Sent via Deja.com
> http://www.deja.com/

--
In the immortal words of Socrates, "I drank what?"

Sent via Deja.com
http://www.deja.com/



Tue, 24 Jun 2003 22:32:18 GMT  
 Problems removing a binding

Quote:
> Thanks!  That did the trick nicely.  I'll have to look up info on
> Tk::NoOp, because I never heard of it until this week.

> Strangely, the chapter on Tk seems to have (literally) disappeared from
> my ActiveState documentation.  Hmmm....

You know, that happened to me too.  I think that I installed build 623
over the previous build, and while that did not affect the installed
Tk software, it did blow away the Tk doc.  "ppm install Tk" fixed
everything.

--
Marc Dashevsky  (remove "_" from address to reply by e-mail)



Tue, 24 Jun 2003 22:56:10 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Removing default bindings?

2. removing bindings

3. remove bind for class

4. Removing a binding from a Text window

5. Remove class binding from a widget

6. HELP - bind does not bind

7. Net::LDAP bind or bound?

8. PERLFUNC: bind - binds an address to a socket

9. PERLFUNC: bind - binds an address to a socket

10. HELP - bind does not bind

11. BIND in perl, no bind

12. Multiple key binding in one bind() call?

 

 
Powered by phpBB® Forum Software