Tkinter binding list

  • Thread starter Rodrigo Benenson
  • Start date
R

Rodrigo Benenson

Hi,

I have a weird need in tkinter. If I have a widget I can *set* a binding

..bind("<the event>", the_callback)


I also can *append* a binding

..bind("<the event>", the_second_callback, "+")

but now, I need to *replace* a callback. The easier way is to obtain the
bindings, delete them all, and rebind the new list.

So, how can I replace a callback, when there are more than one binding ?
or, as an equivalente question,

how can I obtain the list of callbacks binded to widget event ?

Thanks,
RodrigoB.
 
J

Jeff Epler

The bind method with one argument returns the string of tcl code that is
the current binding. For instance:'if {"[136008116<lambda> %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T

The bind method with zero arguments returns all the existing bindings:('<<V>>',)

Jeff
 
E

Eric Brunel

Rodrigo said:
Hi,

I have a weird need in tkinter. If I have a widget I can *set* a binding

.bind("<the event>", the_callback)


I also can *append* a binding

.bind("<the event>", the_second_callback, "+")

but now, I need to *replace* a callback.

What's the difference between "setting" and "replacing" for you? If you set a
callback doing a "return 'break'" at the end, the event should execute your
binding and nothing else. Can you post a script showing exactly what you want to
do and what problems you have?
 
R

Rodrigo Benenson

I mean replacing *one* of the callbacks for the event. Suposing that I do
not know which callbacks were previously set, except the one I want
remplace. If I *set* a callback, all the callback list will be erased.

This is a case in a plugin system. My plugin want to add a hook, but is
probable that other plugins already hooked they own callbacks. I do no want
to delete they callbacks but just to remplace the "root" callback (for which
I already have a reference).

I did this post because I found strange to do not found a way to do this,
maybe it should be a PEP for Tkinter ?

RodrigoB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,474
Latest member
AntoniaDea

Latest Threads

Top