Python3 Gtk new tab

I'm just playing with Gtk currently, but was wondering if someone has an example code of a window that has a notebook in it, and with a click of a button or event, it opens a new tab with a Gtk (for example) entry in it and is accessible from further code.

I can't find any working code like that on the web or on this website.


import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class MyWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Simple Notebook Example")
        self.set_border_width(3)

        self.box = Gtk.VBox(spacing=6)
        self.add(self.box)
        self._add_tab_button = Gtk.Button(label="Add Tab")
        self._add_tab_button.connect("clicked", self.add_tabs)

        self.box.pack_start(self._add_tab_button, False, False, 5)
        self.counter = 1

        self.notebook = Gtk.Notebook()
        self.box.pack_start(self.notebook, True, True, 5)

        # add two tabs
        self.add_tabs(None)
        self.add_tabs(None)

    def add_tabs(self, button):
        page = Gtk.Box()
        page.set_border_width(10)
        page.add(Gtk.Label(label="Page %s content" % self.counter))
        self.notebook.append_page(
            page, Gtk.Label(label="Page %s" % self.counter))
        page.show_all()
        self.counter += 1

win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()