Remove page from TreeBook without destroying panel

Hello folks,

I’m using TreeBook for a project in which I load hundreds or thousands of pages. Even though there are many pages added to the TreeBook, there are only a few ‘types’. Instead of creating hundreds of panels to add for each page, instead I create a blank panel for each type and assign that same panel to all pages of same type. I then dynamically update the content of the panel when the user selects the page.

This has worked well so far except for I’m adding the capability to delete pages from the list and I’m running into problems. TreeBook.DeletePage (and DeleteAllPages) appears to ‘destroy’ the panel too. So after I delete one page, I’m not able to view the other pages that have that same type because the panel is deleted.

So, I have a few questions on trying to solve this issue and would appreciate your input:

  1. Is there a direct way of deleting the page from TreeBook without destroying the panel? I find the destruction of the panel weird as TreeBook doesn’t itself create the panel (it only adds to the list).
  2. Change the panel for the page to None prior to deleting page. Unfortunately it doesn’t seem like there’s a way to set the panel of a page that is already created. Or is there?
  3. Is there a way to remove the page through TreeBook.TreeCtrl that does not mess up TreeBook’s bookkeeping of pages/panels?
  4. Is overwriting the panels (hypothetical) Destroy method to ignore the destruction in specific cases a way to go about it?
  5. Should I be using a different widget?


Hello Michael,

As you have seen, DeletePage destroys the specified page. You can use RemovePage instead.

wx.BookCtrlBase — wxPython Phoenix 4.2.0 documentation
RemovePage (self, page )
Deletes the specified page, without deleting the associated window.

1 Like

That is exactly what I was looking for. It woks as I was hoping it to. I’m not sure how I missed it…