Tkinter: text widget predefined key bindings

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Tue Aug 27 10:17:21 EDT 2002


On Tuesday 27 Aug 2002 1:02 pm, Michele Simionato wrote:
> - I discovered by trials that the text widget recognizes some
> predefined key bindings; for instance C-k delete a line, C-o insert
> a newline,C-e goes at the end of a line, C-t transpose two chars, C-i
> insert a tab, etc. etc. These settings sometimes are useful, sometimes
> are annoying. Suppose for instance I want to rebind, C-k:
>
> text.bind('<Control-k>',lambda event : dosomething())
>
> it works, in the sense that  dosomething() is executed, but
> unfortunately the line is killed too !
>
> text.unbind('<Control-k>') doesn't work.
>
> How can I get rid of these hard coded bindings ?

I don't think you can but if you return "break" from your do_somthing function 
it will not pass on the event to the default binding.

def do_somthing(event):
    ## do somthing then return
    return "break"


>
> - Second question: is there some predefined binding for undo ?
> C-z and C-u do not work. If there is no undo, how could I implement
> some simple undo routine ?
>
> TIA,





More information about the Python-list mailing list