ttk.Notebook – Detect tab change

We can detect when the user changes the current tab selection by binding to a virtual event called <>

img

Bind to a virtual event to detect when the tab selection changes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
my_notebook.bind("<<NotebookTabChanged>>", on_tab_selection_changed)


#!python
def on_tab_selection_changed(event):

    # Get the active tab's text
    tab_text = self.notebook1.tab("current", "text")

    print("The tab has been changed to", tab_text)