Search code examples
pythongtkgtk3

Gtk Notebook call function every time a certain tab is selected


I want a tab on my notebook that pretty much does the same like a button. Every time I select this tab it should execute a certain job (for example print('something') ).

How do I get it to execute every time I open it? Right now it just executes once on startup and that's it.

If someone has some advice on this subject I'd really apreciate some help!


Solution

  • You're looking for the switch-page signal:

    def callback(notebook, tab, index):
        if index == index_of_the_tab:
            print('selected')
    
        # alternatively:
        # if tab is the_tab:
        #     print('selected')
    
    notebook.connect('switch-page', callback)