1

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!

ph.reisich
  • 13
  • 5

2 Answers2

2

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)
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • Thank you, your answer is very useful. How do we utilize a method like this when the current tab is reselected? In my case, I want to utilize the callback when a different tab is selected (Solved by your answer) as well as when the current tab is selected yet again. – Michael Sinclair Jan 05 '21 at 23:15
1

You can use the switch-page signal.

The callback prototype includes the page number id so that you can figure out to which page you are switching.

void user_function (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data)

José Fonte
  • 4,016
  • 2
  • 16
  • 28