My current setup
class AppFrame(wx.Frame):
def__init__(self,parent,id=-1,title='program'):
wx.Frame.__init__(self,parent,id,title,size=((400,400)))
# Panels
self.AppPanel = wx.Panel(self,-1)
self.AppPanel.SetBackgroundColour('grey')
class NBPanel(wx.Notebook):
def__init__(etc)
How do I add this NBPanel class (which im trying to make a notebook panel) inside my AppFrame so that it will show both panels inside my AppFrame. My mind goes bonkers while trying to figure this out. Am I suppose to make the NBPanel class a child of the AppPanel?
such as:
class AppFrame(wx.Frame):
def__init__(self,parent,id=-1,title='Mango'):
wx.Frame.__init__(self,parent,id,title,size=((400,400)))
# Panels
self.AppPanel = wx.Panel(self,-1)
self.AppPanel.SetBackgroundColour('grey')
**self.AppPanel2 = NBPanel(self.AppPanel,-1)**
I tried a few variations of this and basically got a few kinds of errors.
BTW The (AppPanel) isn't as bare as this code shows, it has a sizer set to the left-vertical with a few buttons and such. I want the notebook panel to take most of the middle area of the AppFrame because I'll still need to add another panel to the right of the notebook panel.
You'll still want a panel that covers the whole frame, this will happen automatically if the panel is the only child of the frame.
To get the desired layout you'll want to arrange things in a horizontal box sizer (wx.BoxSizer(wx.HORIZONTAL)
). If you add the sizer with the buttons in first, then add the NBPanel, then add the panel you want on the right next you should get the desired layout.
All of these controls will need the AppPanel as the parent, and you will need to set the horizontal sizer as the AppPanels sizer.
To get the notebook to take up most of the space in the frame you'll want to add it to the sizer with proportion 1 and the other items with 0.
I'd be happy to put together a quick demo if this will make things clearer :)
Here's a quick example that should give an outline for the layout you're after, let me know if you have any questions. Also check out this guide, it's really great and provides a ton of examples to get you started on different programs and layouts.
import wx
class NoteBookPage(wx.Panel):
def __init__(self,parent,message):
wx.Panel.__init__(self,parent)
sizer= wx.BoxSizer(wx.VERTICAL)
message= wx.StaticText(self,label=message)
sizer.Add(message,1,wx.ALIGN_CENTRE)
self.SetSizer(sizer)
class AppFrame(wx.Frame):
def __init__(self,parent,id=-1,title='program'):
wx.Frame.__init__(self,parent,id,title,size=((400,400)))
# Panels
self.AppPanel = wx.Panel(self,-1)
self.AppPanel.SetBackgroundColour('grey')
main_sizer= wx.BoxSizer(wx.HORIZONTAL)
button_sizer= wx.BoxSizer(wx.VERTICAL)
#buttons
self.button1= wx.Button(self.AppPanel,label="Button 1")
button_sizer.Add(self.button1,0,wx.EXPAND)
self.button2= wx.Button(self.AppPanel,label="Button 2")
button_sizer.Add(self.button2,0,wx.EXPAND)
self.button3= wx.Button(self.AppPanel,label="Button 3")
button_sizer.Add(self.button3,0,wx.EXPAND)
main_sizer.Add(button_sizer,0,wx.ALL,5)
#notebook
self.Notebook= wx.Notebook(self.AppPanel)
page1= NoteBookPage(self.Notebook,"I'm on page 1")
page2= NoteBookPage(self.Notebook,"I'm on page 2")
self.Notebook.AddPage(page1,"Page 1")
self.Notebook.AddPage(page2,"Page 2")
main_sizer.Add(self.Notebook,1,wx.ALL|wx.EXPAND,5)
#panel on the right (I'm just re-using the NoteBookPage panel to save making a new one)
right_panel= NoteBookPage(self.AppPanel,"right panel")
main_sizer.Add(right_panel,0,wx.ALL,5)
self.AppPanel.SetSizer(main_sizer)
self.Show()
if __name__ == "__main__":
app= wx.App(False)
frame= AppFrame(None)
app.MainLoop()