Question

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)
Was it helpful?

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

OTHER TIPS

Alright, I'm not sure if that's the proper way to do it, but I found a way that works.

The function to add the page received one more line:

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

and a function to delete the page was written:

def delPage(self, pageTitle):
    for index in range(self.dataNoteBook.GetPageCount()):
        page = self.dataNoteBook.GetPage(index)
        if page.GetLabel() == pageTitle:
            self.dataNoteBook.DeletePage(index)
            self.dataNoteBook.SendSizeEvent()

I'm open for suggestions to get that more efficient! :)

Thomas

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top