Hello,
I am new to wxPython and I am playing around with it. I like it so
far but have run into a problem.
My code is an adaptation of the "StaticBox.py" demo. I have a
GridBagSizer with buttons on it inside of a StaticBoxSizer. That
StaticBoxSizer is then inside a BoxSizer so I can get a border around
it.
When this is initially created, everything looks as expected and sized
properly. However, when I resize my window the buttons in the
GridBagSizer are not being resized. They remain the same size and the
static box overlaps them and they disappear from the window.
My border and static box are being resized properly, but the
GridBagSizer is not resizing.
I have tried to bind to the EVT_SIZE but had no luck.
Any help would be appreciated.
Thanks,
John
···
----------------------------------------------------------------------------------------------
import wx
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
panel = wx.Panel.__init__(self, parent, -1)
# Create the Box and sizer for the outline
box = wx.StaticBox(self, -1, "This is a wx.StaticBox")
self.bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
# Create the sizer and place my controls within it
self.gbs = wx.GridBagSizer(5, 5)
a_btn = wx.Button(self, -1, "Button 1", (-1,-1), (250,100))
b_btn = wx.Button(self, -1, "Button 2", (-1,-1), (250,100))
c_btn = wx.Button(self, -1, "Button 3", (-1,-1), (150,-1))
d_btn = wx.Button(self, -1, "Button 4", (-1,-1), (150,-1))
e_btn = wx.Button(self, -1, "Button 5", (-1,-1), (150,-1))
f_btn = wx.Button(self, -1, "Button 6", (-1,-1), (150,-1))
self.gbs.Add( a_btn, (0,0), (1,1), flag=wx.EXPAND )
self.gbs.Add( b_btn, (2,0), (1,1), flag=wx.EXPAND )
self.gbs.Add( c_btn, (2,1), (1,1), flag=wx.EXPAND )
self.gbs.Add( d_btn, (3,0), (1,1), flag=wx.EXPAND )
self.gbs.Add( e_btn, (3,1), (1,1), flag=wx.EXPAND )
self.gbs.Add( f_btn, (5,0), (1,1), flag=wx.EXPAND )
self.gbs.AddGrowableRow(0)
self.gbs.AddGrowableRow(2)
self.gbs.AddGrowableRow(3)
self.gbs.AddGrowableRow(5)
self.gbs.AddGrowableCol(0)
# Place the Controls within the Static Box Sizer
self.bsizer.Add(self.gbs, 0, wx.TOP|wx.LEFT, 10)
# Place the Static Box Sizer within the Border frame
# Creating a border that my box static box will sit inside
self.border = wx.BoxSizer()
self.border.Add(self.bsizer, 1000, wx.EXPAND|wx.ALL, 20)
self.SetSizer(self.border)
# self.Bind(wx.EVT_SIZE, self.OnResize, self)
def OnResize(self, event):
size = event.GetSize()
# self.SetSizerAndFit(self.gbs)
print size
# self.SetSizer(self.border)
# self.SetSizer(self.bsizer)
# self.SetSizer(self.gbs)
# print "here"
# event.Skip()