1

enter image description hereI need to create a Python frame as shown in the attached picutre.

Let me know how to accomplish it.

enter image description here

There are totally 3 blocks.. 1.header 2.Navigation 3.Main content..

Navigation block should be mutiple frames..each time you select a option it needs to change..

It has to be more like a menu navigation

import random import wx

#

class TabPanel1(wx.Panel): #---------------------------------------------------------------------- def init(self, parent): """""" wx.Panel.init(self, parent=parent)

    colors = ["red", "blue", "gray", "yellow", "green"]
    self.SetBackgroundColour(random.choice(colors))

panel1 = wx.Panel(self,size=(400,100))
panel1.SetBackgroundColour('#4f5049')

panel1gs = wx.GridSizer(2,2,1,2)

panel1gs.AddMany( [ (wx.StaticText(self,label='FirstLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='SecondLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='ThirdLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='FourthLabel'),0,wx.EXPAND)
        ] )

panel1.SetSizer(panel1gs)

panel2 = wx.Panel(self,size=(400,100))
panel2.SetBackgroundColour('#4f5042')

panel3 = wx.Panel(self,size=(400,100))
panel3.SetBackgroundColour('#4f5042')

    btn = wx.Button(self, label="Press Me")
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(btn, 0, wx.ALL, 5)
sizer.Add(panel1, 0, wx.ALL, 5)
sizer.Add(panel2, 0, wx.ALL, 5)
sizer.Add(panel3, 0, wx.ALL, 5)


    self.SetSizer(sizer)

class TabPanel2(wx.Panel): #---------------------------------------------------------------------- def init(self, parent): """""" wx.Panel.init(self, parent=parent)

    colors = ["red", "blue", "gray", "yellow", "green"]
    self.SetBackgroundColour(random.choice(colors))

    btn = wx.Button(self, label="Press Me")
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(btn, 0, wx.ALL, 10)

    self.SetSizer(sizer)
#

class DemoFrame(wx.Frame): """ Frame that holds all other widgets """

#----------------------------------------------------------------------
def __init__(self):
    """Constructor"""        
    wx.Frame.__init__(self, None, wx.ID_ANY, 
                      "Notebook Tutorial",
                      size=(800,600)
                      )
    panel = wx.Panel(self)

    notebook = wx.Notebook(panel)
    tabOne = TabPanel1(notebook)
    notebook.AddPage(tabOne, "Tab 1")

    tabTwo = TabPanel2(notebook)
    notebook.AddPage(tabTwo, "Tab 2")

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
    panel.SetSizer(sizer)
    self.Layout()

    self.Show()

----------------------------------------------------------------------

if name == "main": app = wx.App(False) frame = DemoFrame() app.MainLoop()

Latest changes Newcode.py

import random
import wx


########################################################################
class PanelTextCombo(wx.Panel):
     def __init__(self,parent):
    wx.Panel.__init__(self,parent=parent,size=(400,100))

    self.SetBackgroundColour('blue')

    panel1gs = wx.GridSizer(2,2,1,2)

    panel1gs.AddMany( [ (wx.StaticText(panel1,label='FirstLabel'),0),
            (wx.StaticText(panel1,label='SecondLabel'),0),
            (wx.StaticText(panel1,label='ThirdLabel'),0),
            (wx.StaticText(panel1,label='FourthLabel'),0)
            ] )



    panel1.SetSizer(panel1gs)

class TabPanel1(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent)

        colors = ["red", "blue", "gray", "yellow", "green"]
        #self.SetBackgroundColour(random.choice(colors))
    self.SetBackgroundColour('RED')

    #panel1 = wx.Panel(self,size=(400,100))
    #panel1.SetBackgroundColour('blue')

    #panel1gs = wx.GridSizer(2,2,1,2)

    #panel1gs.AddMany( [ (wx.StaticText(panel1,label='FirstLabel'),0),
    #       (wx.StaticText(panel1,label='SecondLabel'),0),
    #       (wx.StaticText(panel1,label='ThirdLabel'),0),
    #       (wx.StaticText(panel1,label='FourthLabel'),0)
    #       ] )

    #panel1.SetSizer(panel1gs)
    panel1 = PanelTextCombo(TabPanel1)
    #panel2 = wx.Panel(self,size=(400,100))
    #panel2.SetBackgroundColour('green')

    #panel3 = wx.Panel(self,size=(400,100))
    #panel3.SetBackgroundColour('#4f5042')

        btn = wx.Button(self, label="Press Me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 5)
    sizer.Add(panel1, 0, wx.ALL, 5)
    #sizer.Add(panel2, 0, wx.ALL, 5)
    #sizer.Add(panel3, 0, wx.ALL, 5)


        self.SetSizer(sizer)

class TabPanel2(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent)

        colors = ["red", "blue", "gray", "yellow", "green"]
        self.SetBackgroundColour(random.choice(colors))

        btn = wx.Button(self, label="Press Me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 10)

        self.SetSizer(sizer)

########################################################################
class DemoFrame(wx.Frame):
    """
    Frame that holds all other widgets
    """

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""        
        wx.Frame.__init__(self, None, wx.ID_ANY, 
                          "Notebook Tutorial",
                          size=(800,600)
                          )
        panel = wx.Panel(self)

        notebook = wx.Notebook(panel)
        tabOne = TabPanel1(notebook)
        notebook.AddPage(tabOne, "Tab 1")

        tabTwo = TabPanel2(notebook)
        notebook.AddPage(tabTwo, "Tab 2")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
        panel.SetSizer(sizer)
        self.Layout()

        self.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = DemoFrame()
    app.MainLoop()
1
  • I think what you want is a wx.Notebook Commented Sep 20, 2012 at 20:44

1 Answer 1

1

Use a wx.StaticText for the top part as a label, then use a wx.Notebook (or one of the other "book" widgets) for the rest. See the following tutorial:

Sign up to request clarification or add additional context in comments.

4 Comments

I created a Notebook..added 3 panels within it..and it worked..but my requirement is..1st panel within it should contain 3 panels and within each of 3 panels, I will add different controls
You can put three panels into a sizer or you could use a nested Notebook.
Can you check the above piece of code..Im trying to set a sizer for panel1 in page1 but for somereason its nor working
I got the answer..I was not setting the new buttons parent panel is panel1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.