Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Tkinter unbinding (http://www.velocityreviews.com/forums/t649198-tkinter-unbinding.html)

Roger 12-18-2008 04:24 PM

Tkinter unbinding
 
I've done a lot of googling for this topic and I fear that it's not
possible. I have a widget that is overloaded with several bindings.
I want to be able to unbind one method form the same Event without
destroying all the other bindings to the same event that's associated
to the same widget.

For example:

import Tkinter

def test():
print 'test'

def test2():
print 'test2'

root = Tkinter.Tk()
funcid1 = root.bind("<1>", lambda e: test())
funcid2 = root.bind("<1>", lambda e: test2(), add='+')
root.unbind("<1>", funcid2)
root.mainloop()

When run neither <1> binding will exist against the root because the
unbind will unbind all the functions associated with that event.
However, in this example, I only want to unbind test2 not test1.

Any help is greatly appreciated. Thanks!
Roger.

r 12-18-2008 04:32 PM

Re: Tkinter unbinding
 
w.unbind ( sequence, funcid=None )
This method deletes bindings on w for the event described by sequence.
If the second argument is a callback bound to that sequence, that
callback is removed and the rest, if any, are left in place. If the
second argument is omitted, all bindings are deleted.

see
http://infohost.nmt.edu/tcc/help/pub...universal.html

Roger 12-18-2008 04:36 PM

Re: Tkinter unbinding
 
>funcid1 = root.bind("<1>", lambda e: test())
>funcid2 = root.bind("<1>", lambda e: test2(), add='+')
>root.unbind("<1>", funcid2)


Isn't this what I've done in my example code?

r 12-18-2008 04:40 PM

Re: Tkinter unbinding
 
Yea, my answer was really not a helping answer(sorry) just showing
exactly why this will not work with w.unbind(). Why do you need two
separate functions to bind the same event?? You cannot combine the
two??

Roger 12-18-2008 04:52 PM

Re: Tkinter unbinding
 
On Dec 18, 11:40*am, r <rt8...@gmail.com> wrote:
> Yea, my answer was really not a helping answer(sorry) just showing
> exactly why this will not work with w.unbind(). Why do you need two
> separate functions to bind the same event?? You cannot combine the
> two??


I can't combine the two in my app unfortunately. The binding is to a
custom widget that upon it being destroyed the binding is no longer
valid. I can work around this by being hacky but I prefer to delete
the one binding itself which would make things cleaner.

r 12-18-2008 05:49 PM

Re: Tkinter unbinding
 
Maybe someone will chime in with an answer, sorry i could not help.
ponder this, i must...

Roger 12-18-2008 07:11 PM

Re: Tkinter unbinding
 
On Dec 18, 12:49*pm, r <rt8...@gmail.com> wrote:
> Maybe someone will chime in with an answer, sorry i could not help.
> ponder this, i must...


Regardless, thanks for your help! I truly appreciate it.

Roger.

Roger 12-18-2008 07:19 PM

Re: Tkinter unbinding
 
On Dec 18, 12:49*pm, r <rt8...@gmail.com> wrote:
> Maybe someone will chime in with an answer, sorry i could not help.
> ponder this, i must...


Regardless, thanks for your help! I truly appreciate it.

Roger.

Roger 12-18-2008 07:38 PM

Re: Tkinter unbinding
 
On Dec 18, 12:49*pm, r <rt8...@gmail.com> wrote:
> Maybe someone will chime in with an answer, sorry i could not help.
> ponder this, i must...


Regardless, thanks for your help! I truly appreciate it.

Roger.

Roger 12-18-2008 07:48 PM

Re: Tkinter unbinding
 
On Dec 18, 12:49*pm, r <rt8...@gmail.com> wrote:
> Maybe someone will chime in with an answer, sorry i could not help.
> ponder this, i must...


Regardless, thanks for your help! I truly appreciate it.

Roger.


All times are GMT. The time now is 08:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.