• How do I force focus on a widget?

    From Luc@21:1/5 to All on Sat Oct 22 21:04:29 2022
    My application runs this code at startup among other things:

    set ::WidgetThatHasFocusNow [focus]
    if {[string length $::WidgetThatHasFocusNow] <= 0} {
    puts "focus is on [focus]"
    }

    output:
    focus is on


    That means no widget has focus at startup.

    So I fixes it.

    set WidgetThatHasFocusNow [focus]
    if {[string length $::WidgetThatHasFocusNow] <= 0} {
    focus -force $::FileListColumn
    event generate $::FileListColumn <Up>
    puts "focus is on [focus]"
    } else {puts Eureka!}

    output:
    focus is on

    No, it still doesn't work. :-(

    But I also have this:

    bind $::FileListColumn <Key> {after idle [list p.Update.Widgets.On.Any.Action %K]}

    That prints/inserts the output of [focus] on a widget I keep around for debugging.
    So that widget gets focus when I press any key, but not until then in spite of my efforts.

    How can I force focus at startup programatically?

    TIA

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From fr@21:1/5 to Luc on Mon Oct 24 12:55:50 2022
    On Sunday, October 23, 2022 at 2:04:34 AM UTC+2, Luc wrote:
    My application runs this code at startup among other things:

    set ::WidgetThatHasFocusNow [focus]
    if {[string length $::WidgetThatHasFocusNow] <= 0} {
    puts "focus is on [focus]"
    }

    output:
    focus is on


    That means no widget has focus at startup.

    So I fixes it.

    set WidgetThatHasFocusNow [focus]
    if {[string length $::WidgetThatHasFocusNow] <= 0} {
    focus -force $::FileListColumn
    event generate $::FileListColumn <Up>
    puts "focus is on [focus]"
    } else {puts Eureka!}

    output:
    focus is on

    No, it still doesn't work. :-(

    But I also have this:

    bind $::FileListColumn <Key> {after idle [list p.Update.Widgets.On.Any.Action %K]}

    That prints/inserts the output of [focus] on a widget I keep around for debugging.
    So that widget gets focus when I press any key, but not until then in spite of my efforts.

    How can I force focus at startup programatically?

    TIA

    --
    Luc

    What happens, when you insert a line with "update" or "update idletasks" before you query the current focus?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Mon Oct 24 19:46:46 2022
    On Mon, 24 Oct 2022 12:55:50 -0700 (PDT), fr wrote:

    What happens, when you insert a line with "update" or "update idletasks" before you query the current focus?

    It works as intended, that's what happens. :-)

    Just what I needed. Thanks!

    --
    Luc


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