Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter unbinding

Reply
Thread Tools

Tkinter unbinding

 
 
Roger
Guest
Posts: n/a
 
      12-18-2008
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.
 
Reply With Quote
 
 
 
 
r
Guest
Posts: n/a
 
      12-18-2008
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
 
Reply With Quote
 
 
 
 
Roger
Guest
Posts: n/a
 
      12-18-2008
>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?
 
Reply With Quote
 
r
Guest
Posts: n/a
 
      12-18-2008
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??
 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      12-18-2008
On Dec 18, 11:40*am, r <(E-Mail Removed)> 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.
 
Reply With Quote
 
r
Guest
Posts: n/a
 
      12-18-2008
Maybe someone will chime in with an answer, sorry i could not help.
ponder this, i must...
 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      12-18-2008
On Dec 18, 12:49*pm, r <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      12-18-2008
On Dec 18, 12:49*pm, r <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      12-18-2008
On Dec 18, 12:49*pm, r <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      12-18-2008
On Dec 18, 12:49*pm, r <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unbinding Tkinter default bindings for Listbox Roger Python 7 01-13-2009 01:13 AM
Unbinding multiple variables Johnny Lin Python 11 01-24-2005 08:27 PM
Unbinding sockets in threads.. Richard Spooner Python 0 08-03-2004 07:47 AM
Re: UNbinding a socket Sin C++ 2 06-25-2003 06:27 PM
Re: (OT) UNbinding a socket Michael Furman C++ 0 06-23-2003 07:41 PM



Advertisments