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
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
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:17:41 |
Calls: | 6,448 |
Files: | 12,050 |
Messages: | 5,254,338 |