FAQ
Hi All!

I would like to hide and show pages in a notebook. Here is what I do
right now:

def SetVisiblePages(self,pages):
for index in range(self.notebook.GetPageCount()):
self.notebook.GetPage(index).Show(index in pages)

But it does not work. All pages remain visible. Only their content will
be invisible.
I also tried this:

self.notebook.Show(index in pages)

but it hides the whole nootebook. How can I hide/show individual pages?
Thanks in advance.

Laci 2.0

p.s.: I sent this originally to the wxpython-users list but it never
arrived.

Search Discussions

  • Brian Kelley at Mar 25, 2004 at 12:39 am

    Gandalf wrote:
    Hi All!

    I would like to hide and show pages in a notebook. Here is what I do
    right now:

    def SetVisiblePages(self,pages):
    for index in range(self.notebook.GetPageCount()):
    self.notebook.GetPage(index).Show(index in pages)

    But it does not work. All pages remain visible. Only their content will
    be invisible.
    I also tried this:

    self.notebook.Show(index in pages)

    but it hides the whole nootebook. How can I hide/show individual pages?
    Thanks in advance.
    notebook.RemovePage will "hide" a notebook window without deleting it,
    you can add it back later. Here is a small example, you'll probably
    want to do better bookkeeping than I do.

    from wxPython.wx import *

    class MyNoteBook(wxNotebook):
    def __init__(self, *a, **kw):
    wxNotebook.__init__(self, *a, **kw)
    self.pages = {}

    def HidePage(self, pagenum, label):
    page = self.GetPage(pagenum)
    self.pages[label] = page, self.GetPageText(pagenum)
    self.RemovePage(pagenum)

    def ShowPage(self, label):
    if label not in self.pages:
    return
    page, text = self.pages[label]
    self.AddPage(page, text, select=True)

    if __name__ == "__main__":
    app = wxPySimpleApp()
    frame = wxFrame(None, -1, "test")
    sizer = wxBoxSizer(wxVERTICAL)
    notebook = MyNoteBook(frame, -1)
    sizer.Add(notebook, 1, wxEXPAND|wxALL)
    panel1 = wxPanel(notebook, -1)
    panel1.SetBackgroundColour("yellow")
    notebook.AddPage(panel1, "Foo")
    panel2 = wxPanel(notebook, -1)
    panel2.SetBackgroundColour("red")
    notebook.AddPage(panel2, "Bar")
    def hidepageone(evt, notebook=notebook):
    notebook.HidePage(1, "mylabel")
    def showpageone(evt, notebook=notebook):
    notebook.ShowPage("mylabel")

    button1 = wxButton(frame, -1, "Hide Page")
    button2 = wxButton(frame, -1, "Show Page")
    EVT_BUTTON(button1, button1.GetId(), hidepageone)
    EVT_BUTTON(button2, button2.GetId(), showpageone)
    sizer.Add(button1, 0, wxEXPAND)
    sizer.Add(button2, 0, wxEXPAND)
    frame.SetSizer(sizer)
    frame.Show()
    app.MainLoop()
  • Pierre Rouleau at Mar 25, 2004 at 3:56 am

    Gandalf wrote:


    p.s.: I sent this originally to the wxpython-users list but it never
    arrived.
    Just in case, did you post it through news.gmane? If so you have to use
    a real email address and the first time you post you will have to
    register yourself to gmane. See http://gmane.org/.

    Pierre

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 24, '04 at 8:03p
activeMar 25, '04 at 3:56a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase