I have this quite minimal example which gives unexpected layout. I fail to understand why control1 and control2 is layed out differently. control1 looks okay but in control2 the two text labels are on top of each other. Can anyone see what I’m doing wrong?
import wx
RH = 25 # control height
LW = 100 # control width
class MyCustomWidget(wx.Panel):
def __init__(self, parent, value=0, labeltext='', size=(540, 25)):
wx.Panel.__init__(self, parent, wx.ID_ANY, size=size, style=wx.WANTS_CHARS)
self.parmSizer = wx.BoxSizer(wx.HORIZONTAL)
self.label1 = wx.StaticText(self, wx.ID_ANY, labeltext)
self.label2 = wx.StaticText(self, wx.ID_ANY, 'Blah blah')
self.parmSizer.Add(self.label1, 0, wx.ALL, 0)
self.parmSizer.Add(self.label2, 0, wx.ALL, 0)
# layout the widgets
self.SetSizer(self.parmSizer)
class Settings(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, 'Example', size=(600, 300))
self.p = wx.Panel(self, wx.ID_ANY, size = (LW, RH))
# create some sizers
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.control1 = MyCustomWidget(self.p, 0, 'This is control1')
self.control2 = MyCustomWidget(self.p, 0, 'This is control2')
# layout the widgets
mainSizer.Add(self.control1)
mainSizer.Add(self.control2)
self.p.SetSizer(mainSizer)
def main():
app = wx.App()
ex = Settings()
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()