• Correct fous on label in snit widgets

    From Christian Gollwitzer@21:1/5 to All on Thu Dec 30 15:33:42 2021
    Hi all,

    I'm writing a small demo for my image resizing package which displays an
    image in a window and allows to navigate with the mouse (drag around /
    zoom in and out). The image is displayed on a label.

    Zooming is bound to the + and - keys. How do I correctly set the focus
    on the label widget? Below is a small example:

    ============================
    package require Tk
    package require snit

    snit::widget imgviewer {


    component disp

    constructor {} {

    install disp using label $win.l -text "Use + and -" -takefocus true
    pack $disp -expand yes -fill both
    bind $disp <Key-plus> { puts "Plus" }
    bind $disp <Key-minus> { puts "Minus" }

    focus $disp ;# how can this be avoided ?

    }

    }

    imgviewer .img
    pack .img -expand yes -fill both
    pack [ttk::entry .ent]

    ====================================

    It only works if I set the focus explicitly like shown above. The
    -takefocus does not have any effect. However this interferes with other
    widgets packed into the same frame. If one sets the input focus to teh
    entry, then it is impossible to set it back to the label again.

    How to handle it correctly?

    The full code is here:

    https://github.com/auriocus/PhotoResize/blob/master/demo/imgviewer.tcl


    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Werner@21:1/5 to All on Thu Dec 30 07:04:38 2021
    Howdy Christian,

    use "-takefocus 1" instead of "-takefocus true"

    BR,
    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Thu Dec 30 18:24:48 2021
    Am 30.12.21 um 16:04 schrieb Christian Werner:
    Howdy Christian,

    use "-takefocus 1" instead of "-takefocus true"


    Hi Christian,

    thank you - it now works reasonably well. The scaling is done on the
    CPU, therefore it is not as smooth as it could be, but there are only
    minimal dependencies Tk and C++). You might want to try it on Android ;)

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)