I'm relatively new to programming in wxPython and I have been trying to put a BoxSizer within a wx.Window. This only results in a small square (which is the panel within the BoxSizer) appearing in the window. Could somebody please tell me what I'm doing wrong?

Sample code:

class TestPanel(wx.Frame):
  def __init__(self, parent, id):
  wx.Frame.__init__(self, parent, -1, size = (800, 400))

    win = wx.Window (self, -1)

    box = wx.BoxSizer(wx.VERTICAL)
    panel2 = wx.Panel(win)
    panel2.SetBackgroundColour("Red")
    box.Add(panel2, 1, wx.EXPAND, 10)
    self.SetSizer(box)

Thanks in advance!

Edited 3 Years Ago by happygeek: fixed formatting

Is this what you want ...

import wx

class TestPanel(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, -1,
            'wx.BoxSizer test', size = (800, 400))

        #win = wx.Window (self, -1)

        box = wx.BoxSizer(wx.VERTICAL)
        panel1 = wx.Panel(self)
        panel1.SetBackgroundColour("green")
        # 1=stretch allowed, and use 10 pixel border
        box.Add(panel1, 1, wx.ALL|wx.EXPAND, 10)
        panel2 = wx.Panel(self)
        panel2.SetBackgroundColour("Red")
        box.Add(panel2, 1, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(box)

        # show the frame
        self.Show(True)

app = wx.PySimpleApp()
tp = TestPanel(None, -1)
app.MainLoop()
This question has already been answered. Start a new discussion instead.