• Bind notebook and and all children

    From Alexandru@21:1/5 to All on Mon Nov 15 13:05:41 2021
    Hi,

    I want to bind a notebook tab to the key combination CTRL-W (close the tab).

    I realize, this works only of the tab has focus.
    If a child widget inside that tab (e.g. treectrl) has the focus, the binding does not get triggered.

    Is there a way to achieve this without having to bind to all children of the notebook tab?

    Thanks
    Alexandru

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Tue Nov 16 06:22:20 2021
    Try binding to the toplevel containing the notebook (one of the default binding tags for any window):

    bind .top <Control-w> [list ckwin .top.nb %X %Y]

    Then use the root coordinates of the event to find the child window:

    winfo containing $x $y

    finally search the child window's parents, if it is a child of the notebook tab, do something.
    using a proc like:

    proc ckwin {nbwin x y} {
    set w [winfo containing $x $y]
    while {"" ne $w} {
    if {$nbwin eq $w} {
    puts "key in $nbwin"
    return
    }
    set w [winfo parent $w]
    }
    puts "key not in $nbwin"
    }


    or add a bindtag to all child windows of the notebook tab, then bind to that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Tue Nov 16 11:52:10 2021
    Am 15.11.21 um 22:05 schrieb Alexandru:
    Hi,

    I want to bind a notebook tab to the key combination CTRL-W (close the tab).

    I realize, this works only of the tab has focus.
    If a child widget inside that tab (e.g. treectrl) has the focus, the binding does not get triggered.

    Is there a way to achieve this without having to bind to all children of the notebook tab?

    Thanks
    Alexandru


    The following example shows a more user-friendly way to make the tabs of
    a ttk::notebook widget closable by the user:

    package require scrollutil_tile
    scrollutil::addclosetab My.TNotebook
    ttk::notebook .nb -style My.TNotebook ...

    The tabs of the notebook created in this way will contain a "closetab"
    element, which, when clicked, will close the tab in question.

    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexandru@21:1/5 to nemethi on Thu Nov 18 02:57:29 2021
    nemethi schrieb am Dienstag, 16. November 2021 um 11:52:14 UTC+1:
    Am 15.11.21 um 22:05 schrieb Alexandru:
    Hi,

    I want to bind a notebook tab to the key combination CTRL-W (close the tab).

    I realize, this works only of the tab has focus.
    If a child widget inside that tab (e.g. treectrl) has the focus, the binding does not get triggered.

    Is there a way to achieve this without having to bind to all children of the notebook tab?

    Thanks
    Alexandru

    The following example shows a more user-friendly way to make the tabs of
    a ttk::notebook widget closable by the user:

    package require scrollutil_tile
    scrollutil::addclosetab My.TNotebook
    ttk::notebook .nb -style My.TNotebook ...

    The tabs of the notebook created in this way will contain a "closetab" element, which, when clicked, will close the tab in question.

    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba....@t-online.de

    Thanks Csaba for the tip. I tried it and I love it! The new close button in the tab Looks awesome.


    Thanks
    Alex

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexandru@21:1/5 to clt.to...@dfgh.net on Thu Nov 18 02:53:25 2021
    clt.to...@dfgh.net schrieb am Dienstag, 16. November 2021 um 07:22:26 UTC+1:
    Try binding to the toplevel containing the notebook (one of the default binding tags for any window):

    bind .top <Control-w> [list ckwin .top.nb %X %Y]

    Then use the root coordinates of the event to find the child window:

    winfo containing $x $y

    finally search the child window's parents, if it is a child of the notebook tab, do something.
    using a proc like:

    proc ckwin {nbwin x y} {
    set w [winfo containing $x $y]
    while {"" ne $w} {
    if {$nbwin eq $w} {
    puts "key in $nbwin"
    return
    }
    set w [winfo parent $w]
    }
    puts "key not in $nbwin"
    }


    or add a bindtag to all child windows of the notebook tab, then bind to that.
    Thanks for the help. I'll implement your example.
    Regards
    Alexandru

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