Tkinter: text widget predefined key bindings

David LeBlanc whisper at oz.net
Tue Aug 27 18:29:27 EDT 2002


http://www2.clearlight.com/~oakley/tcl/supertext.html

Tk text control with infinite udo. Using it in Python is an exercise for the
reader (trans: I dunno how to! ;) ). Another nearby thread is discussing
this as I type...

Regards,

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Eric Brunel
> Sent: Tuesday, August 27, 2002 10:06
> To: python-list at python.org
> Subject: Re: Tkinter: text widget predefined key bindings
>
>
> 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 ?
>
> The bindings are not done at the widget level, but at the class
> level. Try:
>
> text.bind_class('Text', '<Control-k>', lambda e: None)
> text.bind('<Control-k>', lambda event : dosomething())
>
> and it should work as you expect.
>
> > - 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 ?
>
> AFAIK, you can't... And implementing an undo function is always quite a
> PITA, because sooooooooo many things can happen to your text that
> Tk/Tkinter won't care to warn you about... I heard some Tk extension
> package (Blt?) had a Text widget with a built-in undo function,
> but I never
> used it.
>
> HTH
> --
> - Eric Brunel <eric.brunel at pragmadev.com> -
> PragmaDev : Real Time Software Development Tools -
http://www.pragmadev.com
--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list