Am 15.03.22 um 09:47 schrieb Alexandru:
How to specify a command when using close button of notebook tab?
I'm using
scrollutil::addclosetab Closable.TNotebook
ttk::notebook .notebook -style Closable.TNotebook
to add nice close buttons to all tabs of a notebook.
As I could read from the source code of scrollutil, the addclosetab command only modifies the style of the tab. I could not find anything close to a -command option or binding.
The reason for my question: I need control over what happens when the user clicks on that close button.
Many thanks
Alexandru
As of Scrollutil 1.13, the reaction on pressing and later releasing the
left mouse button over a "closetab" element is implemented by lines 1113
- 1114 of the file scrollednotebook.tcl:
$nb forget $tabIdx
set closed 1
Try replacing these lines with:
if {$userDataSupported} {
event generate $w <<CloseTabRequested>> -data $tabIdx
set closed 0
} else {
$nb forget $tabIdx
set closed 1
}
For Tk versions 8.5a2 and later, this will send a <<CloseTabRequested>
virtual event to the notebook, which you can handle in your application
like in the following example:
bind .notebook <<CloseTabRequested>> { closeTab %W %d }
proc closeTab {nb tabIdx} {
set btn [tk_messageBox -title "Close Tab?" -icon question \
-message "Do you really want to close the tab?" -type yesno]
if {$btn eq "no"} {
return ""
}
$nb forget $tabIdx
#
# Optionally:
#
set widget [lindex [$nb tabs] $tabIdx]
event generate $nb <<NotebookTabClosed>> -data $widget
}
I am thinking about incorporating the above change into the next
Scrollutil version.
Notice that if you use a scrollutil::scrollednotebook instead of a ttk::notebook then you can make use of the "-forgetcommand" option to
control whether the "closetab" element will effectively close the tab.
--
Csaba Nemethi
https://www.nemethi.de mailto:
[email protected]
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)