• How to make Ctrl+A select all in a ttk::combox's entry

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Sat Nov 15 07:52:32 2025
    From Newsgroup: comp.lang.tcl

    I want Ctrl+A to select all in a ttk::combobox's entry.
    But I can't get it to work. Here's an example
    (I'm using Tcl/Tk 9.0.2 on Linux):

    #!/usr/bin/env wish9
    proc on_select_all widget {
    puts "on_select_all $widget"
    $widget selection range 0 end
    }
    tk scaling 2
    wm title . ComboTest
    ttk::combobox .combo -values {One Two Three}
    .combo set Three
    pack .combo -fill x -expand true
    bind .combo <Control-a> {on_select_all %W}
    bind . <Escape> exit
    wm protocol . WM_DELETE_WINDOW exit
    focus .combo

    When I press Ctrl+A it correctly prints the widget,
    but it doesn't do the select. What am I doing wrong?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From nemethi@csaba.nemethi@t-online.de to comp.lang.tcl on Sat Nov 15 15:45:25 2025
    From Newsgroup: comp.lang.tcl

    Am 15.11.25 um 08:52 schrieb Mark Summerfield:
    I want Ctrl+A to select all in a ttk::combobox's entry.
    But I can't get it to work. Here's an example
    (I'm using Tcl/Tk 9.0.2 on Linux):

    #!/usr/bin/env wish9
    proc on_select_all widget {
    puts "on_select_all $widget"
    $widget selection range 0 end
    }
    tk scaling 2
    wm title . ComboTest
    ttk::combobox .combo -values {One Two Three}
    .combo set Three
    pack .combo -fill x -expand true
    bind .combo <Control-a> {on_select_all %W}
    bind . <Escape> exit
    wm protocol . WM_DELETE_WINDOW exit
    focus .combo

    When I press Ctrl+A it correctly prints the widget,
    but it doesn't do the select. What am I doing wrong?

    Append

    return -code break

    as last line to the body of the on_select_all proc. For the explanation search for "Control-a" in the ttk_entry manual page.
    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Sat Nov 15 20:28:21 2025
    From Newsgroup: comp.lang.tcl

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    I want Ctrl+A to select all in a ttk::combobox's entry.
    But I can't get it to work. Here's an example
    (I'm using Tcl/Tk 9.0.2 on Linux):

    #!/usr/bin/env wish9
    proc on_select_all widget {
    puts "on_select_all $widget"
    $widget selection range 0 end
    }
    tk scaling 2
    wm title . ComboTest
    ttk::combobox .combo -values {One Two Three}
    .combo set Three
    pack .combo -fill x -expand true
    bind .combo <Control-a> {on_select_all %W}
    bind . <Escape> exit
    wm protocol . WM_DELETE_WINDOW exit
    focus .combo

    When I press Ctrl+A it correctly prints the widget,
    but it doesn't do the select. What am I doing wrong?

    This change makes your code work:

    -bind .combo <Control-a> {on_select_all %W}
    +bind .combo <Control-a> {on_select_all %W ; break}

    There seems to be some other binding getting fired after your's that is undoing the selection for you.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Sun Nov 16 08:23:02 2025
    From Newsgroup: comp.lang.tcl

    On Sat, 15 Nov 2025 15:45:25 +0100, nemethi wrote:

    Am 15.11.25 um 08:52 schrieb Mark Summerfield:
    I want Ctrl+A to select all in a ttk::combobox's entry.
    But I can't get it to work. Here's an example
    (I'm using Tcl/Tk 9.0.2 on Linux):

    #!/usr/bin/env wish9
    proc on_select_all widget {
    puts "on_select_all $widget"
    $widget selection range 0 end
    }
    tk scaling 2
    wm title . ComboTest
    ttk::combobox .combo -values {One Two Three}
    .combo set Three
    pack .combo -fill x -expand true
    bind .combo <Control-a> {on_select_all %W}
    bind . <Escape> exit
    wm protocol . WM_DELETE_WINDOW exit
    focus .combo

    When I press Ctrl+A it correctly prints the widget,
    but it doesn't do the select. What am I doing wrong?

    Append

    return -code break

    as last line to the body of the on_select_all proc. For the explanation search for "Control-a" in the ttk_entry manual page.

    Thank you (& Rich) for your replies. It seems that ttk::entry supports
    some emacs keystrokes. Using break it now works great!

    --- Synchronet 3.21a-Linux NewsLink 1.2