gridSizer inside a panel element

Iain King iainking at gmail.com
Fri Aug 22 15:51:38 CEST 2008


On Aug 22, 2:09 pm, Gandalf <goldn... at gmail.com> wrote:
> why when I try to insert gridSizer to a panel which already inside
> another panel the gridSizer doesn't work?
>
> this is the code:
>
> panel3= wx.Panel(self, -1, (0, 60), size=(400, 240) ,
> style=wx.SIMPLE_BORDER);
>         panel3.SetBackgroundColour('#dadadb')
>         panel = wx.Panel(panel3, wx.ID_ANY, style=wx.SIMPLE_BORDER,
> size=(150, 60))
>         panel.SetBackgroundColour("#fffFFF")
>
>         bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16,
> 16))
>         inputIco = wx.StaticBitmap(panel, wx.ID_ANY, bmp)
>
>         labelThree= wx.StaticText(panel, wx.ID_ANY, 'Hello')
>
>         label2=wx.StaticText(panel, wx.ID_ANY, 'Pease, Quite, Hello, Shalom')
>         topSizer  = wx.BoxSizer(wx.VERTICAL)
>         gridSizer = wx.GridSizer(rows=2, cols=1, hgap=5, vgap=5)
>         input = wx.BoxSizer(wx.HORIZONTAL)
>         output = wx.BoxSizer(wx.HORIZONTAL)
>
>         input.Add((20,20), 1, wx.EXPAND) # this is a spacer
>         input.Add(inputIco, 0, wx.ALL, 5)
>         input.Add(labelThree, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
>
>         output.Add((20,20), 1, wx.EXPAND) # this is a spacer
>
>         output.Add(label2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
>
>         gridSizer.Add(input, 0, wx.ALIGN_LEFT)
>         gridSizer.Add(output, 0, wx.ALIGN_RIGHT)
>
>         topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5)
>         panel.SetSizer(topSizer)

I'm not sure you can just add sizers together like that.  When I'm
doing this I'd make panels for each sub-sizer; so input and output
would be panels rather than the sizers themselves.  For example
(untested):

grid = wx.Panel(panel, wx.ID_ANY)

input = wx.Panel(grid, wx.ID_ANY)
inputIco = wx.StaticBitmap(input, wx.ID_ANY, bmp)
labelThree= wx.StaticText(input, wx.ID_ANY, 'Hello')
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.Add((20,20), 1, wx.EXPAND) # this is a spacer
sz.Add(inputIco, 0, wx.ALL, 5)
sz.Add(labelThree, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
input.SetSizer(sz)

output = = wx.Panel(grid, wx.ID_ANY)
label2=wx.StaticText(output, wx.ID_ANY, 'Pease, Quite, Hello, Shalom')
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.Add((20,20), 1, wx.EXPAND) # this is a spacer
sz.Add(label2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
output.SetSizer(sz)

sz = wx.GridSizer(rows=2, cols=1, hgap=5, vgap=5)
sz.Add(input, 0, wx.ALIGN_LEFT)
sz.Add(output, 0, wx.ALIGN_RIGHT)
grid.SetSizer(sz)

sz = wx.BoxSizer(wx.VERTICAL)
sz.Add(grid, 0, wx.ALL|wx.EXPAND, 5)
panel.SetSizer(sz)

Iain



More information about the Python-list mailing list