pythonwxpythonwxnotebook

How to delete a notebook page?


I have a wxPython GUI where I add pages to a notebook using checkboxes. Every time the checkbox changes its status to 'True' a page is added. But how do I delete the page when the checkbox changes status to 'False'?

There are a couple if checkboxes, so I have to get the id of the page first, but how on earth can I do this? The page is created that way:

def addPage(self, pageTitle):
    page = Page(self.dataNoteBook)
    self.dataNoteBook.AddPage(page, pageTitle)

Solution

  • This is slightly shorter and stops once it finds the named page.

    def delPage(self, pageTitle):
        for index in range(self.dataNoteBook.GetPageCount()):
            if self.dataNoteBook.GetPageText(index) == pageTitle:
                self.dataNoteBook.DeletePage(index)
                self.dataNoteBook.SendSizeEvent()
                break