code: def OnSeriesChanged(self, event):
          
  
          selection = event.GetSelection()
  
          if not self.updating and \
             selection == self.series_notebook.GetPageCount() - 1:
              # Add new series
              new_panel = SeriesPanel(self, {"type": "plot"})
              self.series_notebook.InsertPage(selection, new_panel, _("Series"))
  
          event.Skip()
docs: FlatNotebook change event handler