Re: Canvas' inexplicable behavior with keystrokes



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.
.



Relevant Pages

  • Re: Canvas inexplicable behavior with keystrokes
    ... won't work with a text widget as it requires me to have multiple ... proof of concept as to how to use canvas directly as a text editor. ... Whenever I press the left arrow, ... "Canvas has default bindings to allow scrolling if necessary: ...
    (comp.lang.perl.tk)
  • Re: Canvas inexplicable behavior with keystrokes
    ... won't work with a text widget as it requires me to have multiple ... proof of concept as to how to use canvas directly as a text editor. ... Whenever I press the left arrow, ... These bindings allow you to navigate the same way as in other ...
    (comp.lang.perl.tk)
  • Re: ttk::checkbutton - I think, its a bug
    ... Sorry, my mistake, the bindings are part of the Controller. ... the checkbutton that change the model. ... What I'm trying to say is that and other widgets does not ... expressiveness due to the simple syntax. ...
    (comp.lang.tcl)
  • Re: ::ttk::notebook and bindings
    ... I managed to have shortcuts things working if the bindings were set ... At least one of the tabs must be "active" (with the dotted line ... bindings to widgets in a "inactive" tab. ... all]] also allows activation of widgets in inactive tabs. ...
    (comp.lang.tcl)
  • Re: Binding images to mouseclicks
    ... to the canvas itself and do your own intersection (and the intersection logic seems wrong unless ... i changed the canvas bindings to the ...   global sid ...
    (comp.lang.tcl)