wxpython setsizer
Question: The panel1 in page1 of the Notebook is defined with Size(400,100)..I don't
want the Sizer to resize my panel..

test.py

    
    
    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('brown')
    
        panel1gs = wx.GridSizer(2,2,1,2)
    
        panel1gs.AddMany( [ (wx.StaticText(panel1,label='FirstLabel'),0,wx.EXPAND),
                (wx.StaticText(panel1,label='SecondLabel'),0,wx.EXPAND),
                (wx.StaticText(panel1,label='ThirdLabel'),0,wx.EXPAND),
                (wx.StaticText(panel1,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()
    


Answer: There are two ways a sizer can change the size of an item inside it.

First is the [`wx.EXPAND` flag](http://wxpython.org/docs/api/wx.SizerFlags-
class.html#Expand) which "will cause the item to be expanded to fill as much
space as it is given by the sizer." You're using this flag but you don't want
this behaviour, so you should remove them.

Second, `wx.BoxSizer`s can resize objects using the `proportion` argument in
the [`Add()` and `AddMany()` methods](http://wxpython.org/docs/api/wx.Sizer-
class.html#Add). [`wx.BoxSizer`'s
documentation](http://wxpython.org/docs/api/wx.BoxSizer-class.html) states "

> [objects in the sizer] can grow in both directions (height and width) [...]
> This is determined by the proportion parameter give to items when they are
> added to the sizer. It is interpreted as a weight factor, i.e. it can be
> zero, **indicating that the window may not be resized at all** , or above
> zero.

(Emphasis added)

In your case, you are already setting the proportion to 0 and you aren't even
using a `wx.BoxSizer` so this isn't an issue for you, but it's something to
keep in mind in the future.

