Re: Canvas' inexplicable behavior with keystrokes
- From: Lamprecht <ch.l.ngre-nospam@xxxxxxxxx>
- Date: Mon, 09 Feb 2009 11:04:23 +0100
smallpond schrieb:
On Feb 7, 5:08 pm, "t.kane" <t.k...@xxxxxxxxxxxxxx> wrote:I am trying to create an equation editor. Doing this is something that
won't work with a text widget as it requires me to have multiple
baselines to accommodate sub- and superscripts, as well as having
multiple fonts. I've been working with a small example just to perform
proof of concept as to how to use canvas directly as a text editor. I
can handle taking in keystrokes and adding them to the text on the
canvas in a text item. But I'm having a problem handling the keyboard
arrow keys. Whenever I press the left arrow, my keystroke binding
works correctly, but the entire canvas shifts to the right. I'm
hopeful that there will be some way to lock the canvas into place so
it doesn't move, and I've looked at a number of ways at doing that,
but nothing has worked for me so far. Note that it makes no difference
if I bind the left arrow separately, or even if I bind the left arrow
to the main window directly. Are there any suggestions?
Not inexplicable. If you read perldoc Tk::Canvas it says:
"Canvas has default bindings to allow scrolling if necessary:
<Up>, <Down>, <Left> and <Right> (and their <Control-*>
counter parts). Further <Prior>, <Next>, <Home> and <End>.
These bindings allow you to navigate the same way as in other
widgets that can scroll."
See bindtags for why class bindings take precedence over
widget bindings. Always seemed like a bug to me. In any
case, bindtags lets you change the order so that you can
override the defaults or you can subclass the canvas to
make your own without the same class bindings.
Also, if you don't need these default bindings in other places of your application, removing them is as simple as:
$mw->bind('Tk::Canvas',"<$_>",undef)for qw /Left Right Up Down/;
(Called after creation of at least one Canvas instance)
Christoph
--
Tk::EntrySet
display/edit a list of values in a Set of Widgets.
Tk::ChoicesSet
display/edit a list of choices in a Set of single-selection Widgets.
.
- Follow-Ups:
- Re: Canvas' inexplicable behavior with keystrokes
- From: t.kane
- Re: Canvas' inexplicable behavior with keystrokes
- References:
- Canvas' inexplicable behavior with keystrokes
- From: t.kane
- Re: Canvas' inexplicable behavior with keystrokes
- From: smallpond
- Canvas' inexplicable behavior with keystrokes
- Prev by Date: Re: Canvas' inexplicable behavior with keystrokes
- Next by Date: Re: Canvas' inexplicable behavior with keystrokes
- Previous by thread: Re: Canvas' inexplicable behavior with keystrokes
- Next by thread: Re: Canvas' inexplicable behavior with keystrokes
- Index(es):
Relevant Pages
|