[Tkinter-discuss] Unwanted Text widget bindings

Michael Lange klappnase at web.de
Thu Apr 14 21:47:00 CEST 2005

On Thu, 14 Apr 2005 13:16:11 -0400
Cam <camfarnell at cogeco.ca> wrote:

> Hello list,
> I'm running on a Debian/Gnome Linux box.
> The "Text" widget comes with a bunch of free bindings to various control 
> codes, <Control-a> for "home", <Control-B> for "cursor left" and so on, 
> none of which I want for my application. Most of these I can get rid of 
> by doing w.unbind_class('Text','<Control-whatever>'), but the bindings 
> for Control-x (cut), Control-c (copy) and Control-v (paste) are 
> different; they persist even after unbind, unbind_class and unbind_all.
> I know you CAN get rid of them because Guido manages it just fine in 
> Idle. However, several hours of pouring over the Idle source has not 
> left me any closer to figuring out just how Idle manages to defeat these 
> bindings.
> If any of you list members know what the secret is or can point me to 
> some documentation that covers this issue I would *very* much appreciate it.
> Thanks
> Cam Farnell

You can get rid of the default bindings if you replace them with a "dummy" callback that prevents
the event from being propagated to the widget:

>>> r=Tk()
>>> t=Text(r)
>>> t.pack()
>>> t.bind('<Control-x>', lambda event : 'break')

I hope this helps


More information about the Tkinter-discuss mailing list