Close/destroy wx.Notebook

39 views
Skip to first unread message

floati...@gmail.com

unread,
Nov 21, 2017, 1:48:59 AM11/21/17
to wxPython-users
I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

Tim Roberts

unread,
Nov 21, 2017, 3:04:30 AM11/21/17
to wxpytho...@googlegroups.com
On Nov 20, 2017, at 10:48 PM, floati...@gmail.com wrote:
>
> I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

The notebook is a parent of its pages. You should be able to do something like self.GetParent().Close()

Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

floati...@gmail.com

unread,
Nov 21, 2017, 5:39:52 AM11/21/17
to wxPython-users
Sorry no, that doesn't work, no effect and no error!

Tim Roberts

unread,
Nov 21, 2017, 1:06:51 PM11/21/17
to wxpytho...@googlegroups.com
floati...@gmail.com wrote:
>
> Sorry no, that doesn't work, no effect and no error!

Perhaps you should show us your code.  It's unusual to want to close a
notebook by itself.  Is your notebook the sole window inside a frame,
and it's really the frame you want to close?

--
Message has been deleted

floati...@gmail.com

unread,
Nov 21, 2017, 1:51:54 PM11/21/17
to wxPython-users
OK, here it is. Much simplified to make for easier reading! All I want is for the button to close the entire notebook.

import wx


class info(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
       
self.button1 = wx.Button(self,-1,"close")
       
self.button1.Bind(wx.EVT_BUTTON, self.onClose)
       
       
   
def onClose(self, event):
       
self.Close()  
       
       
class sched1(wx.Panel):
   
def __init__(self, parent):
        wx
.Frame.__init__(self, parent)
       
pass
       

   
def onClose(self, event):
       
self.Close()

       
class sched2(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass
       


class view(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass
       

class history(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass

       
       
###################################Main page##########################################            

class MainFrame(wx.Frame):
   
def __init__(self):
        wx
.Frame.__init__(self, None, title="notebook", size = (600,300))
        p
= wx.Panel(self)
       
self.nb = wx.Notebook(p)

       
self.nb.AddPage(info(self.nb), "Detail")
       
self.nb.AddPage(sched1(self.nb), "Scheduling 1")
       
self.nb.AddPage(sched2(self.nb), "Scheduling 2")
       
self.nb.AddPage(history(self.nb), "History")
       
self.nb.AddPage(view(self.nb), "Additional info")

        sizer
= wx.BoxSizer()
        sizer
.Add(self.nb, 1, wx.EXPAND)
        p
.SetSizer(sizer)


       
if __name__ == "__main__":
    app
= wx.App(True)
   
MainFrame().Show()
    app
.MainLoop()



Thanks.

Tim Roberts

unread,
Nov 21, 2017, 2:15:36 PM11/21/17
to wxpytho...@googlegroups.com
floati...@gmail.com wrote:
>
> OK, here it is. Much simplified to make for easier reading! All I want
> is for the button to close the entire notebook.

Well, here's the issue.   I don't think that's really what  you want. 
This will do what you asked for:
      
    def onClose(self, event):
        self.GetParent().Destroy()

But that leaves an empty frame window.  To do what I expect you really
want, which is to close the frame window, do this:
      
    def onClose(self, event):
        self.GetTopLevelParent().Close()

floati...@gmail.com

unread,
Nov 21, 2017, 2:21:28 PM11/21/17
to wxPython-users
Tim. That is exactly what I needed. Many thanks.
Reply all
Reply to author
Forward
0 new messages