Overriding key bindings in tktext

Does tktext let me completely override bindings? For instance, if I
wanted to disable the enter key, editor.bind(“Any-Key-Return”) {}
doesn’t do anything - the newline gets inserted.

martin

From: Martin DeMello [email protected]
Subject: overriding key bindings in tktext
Date: Wed, 9 Dec 2009 02:58:01 +0900
Message-ID:
[email protected]

Does tktext let me completely override bindings? For instance, if I
wanted to disable the enter key, editor.bind(“Any-Key-Return”) {}
doesn’t do anything - the newline gets inserted.

You have to break the evaluation of the widget’s bindtag list.
By default, the bindtag list is [the_widget, TkText,
toplevel_window_of_the_widget, “all”].
You define a binding to the_widget. But after the callback,
Tk evaluates bindings of TkText (depends on the order of bindtags list).

You can break the evaluation of bindtags by
editor.bind(“Any-Key-Return”){…; break; …}
or editor.bind(“Any-Key-Return”){…; Tk.callback_break; …}.
If the former has no effect (depends on Ruby or Ruby/Tk version),
please use the latter.
The latter should work on any version of Ruby/Tk.

On Wed, Dec 9, 2009 at 5:17 AM, Hidetoshi NAGAI [email protected]
wrote:

please use the latter.
The latter should work on any version of Ruby/Tk.

Thanks, that works beautifully!

martin