Making buttons fill a sizer

I'm developing an interface for a touch screen, where I want the
buttons to fill all available space in a sizer. Unfortunately, I can't
seem to find the incantation to make this work. In the following code,
the buttons fill the screen horizontally, but I'd also like them to
fill the space vertically. Essentially, I want all the space on the
panel to be used by the two buttons.

import wx

class MyFrame(wx.Frame):
   def __init__(self, parent, ID, title):
       wx.Frame.__init__(self, parent, ID, title, size=(300, 250))

       btn1 = wx.Button(self, 1, "Hello")
       btn2 = wx.Button(self, 2, "World")

       sizer = wx.BoxSizer(wx.HORIZONTAL)
       sizer.Add(btn1, proportion=1, flag = wx.EXPAND|wx.GROW)
       sizer.Add(btn2, proportion=1, flag = wx.EXPAND|wx.GROW)
       self.SetSizer(sizer)

app = wx.PySimpleApp()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show()
app.MainLoop()

Any thoughts? I'm sure it's an easy answer, I just haven't got a
strong enough understanding of sizers to work it out.

Jay P.

Hello,

···

On Mon, Mar 23, 2009 at 3:05 PM, Jay Parlar parlar@gmail.com wrote:

Any thoughts? I’m sure it’s an easy answer, I just haven’t got a
strong enough understanding of sizers to work it out.

Horizontal sizers only work in the horizontal direction. So you need to put your Horizontal sizer inside a vertical one so you get the sizing in both directions.

vsizer = wx.BoxSizer(wx.VERTICAL)

vsizer.Add(sizer, 1, wx.EXPAND)

self.SeSizer(vsizer)

Cody

Jay Parlar wrote:

I'm developing an interface for a touch screen, where I want the
buttons to fill all available space in a sizer. Unfortunately, I can't
seem to find the incantation to make this work. In the following code,
the buttons fill the screen horizontally, but I'd also like them to
fill the space vertically. Essentially, I want all the space on the
panel to be used by the two buttons.

import wx

class MyFrame(wx.Frame):
   def __init__(self, parent, ID, title):
       wx.Frame.__init__(self, parent, ID, title, size=(300, 250))

       btn1 = wx.Button(self, 1, "Hello")
       btn2 = wx.Button(self, 2, "World")

       sizer = wx.BoxSizer(wx.HORIZONTAL)
       sizer.Add(btn1, proportion=1, flag = wx.EXPAND|wx.GROW)
       sizer.Add(btn2, proportion=1, flag = wx.EXPAND|wx.GROW)
       self.SetSizer(sizer)

app = wx.PySimpleApp()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show()
app.MainLoop()

Any thoughts? I'm sure it's an easy answer, I just haven't got a
strong enough understanding of sizers to work it out.

Jay P.

Hmmm...this appears to work on Windows XP, wxPython 2.8.9.2, Python 2.5.2. See attached screenshot.

Mike

Interesting. I'm testing on OS X, 2.8.9.2, Python 2.5.2, and the same
on Linux. Cody's solution of using a vertical sizer with the
horizontal sizer works on Linux, but not OS X. It doesn't work in my
actual application for some reason, just in that test code, but that
should be enough of a start to get me going.

Jay P.

···

2009/3/23 Mike Driscoll <mike@pythonlibrary.org>:

Hmmm...this appears to work on Windows XP, wxPython 2.8.9.2, Python 2.5.2.
See attached screenshot.

Hello,

···

On Mon, Mar 23, 2009 at 3:46 PM, Jay Parlar parlar@gmail.com wrote:

2009/3/23 Mike Driscoll mike@pythonlibrary.org:

Hmmm…this appears to work on Windows XP, wxPython 2.8.9.2, Python 2.5.2.
See attached screenshot.

Interesting. I’m testing on OS X, 2.8.9.2, Python 2.5.2, and the same
on Linux. Cody’s solution of using a vertical sizer with the

horizontal sizer works on Linux, but not OS X. It doesn’t work in my
actual application for some reason, just in that test code, but that
should be enough of a start to get me going.

Regular (wx.Button) buttons on OSX are not able to be vertically resized like this. So they cannot be used this way. You can look at using the Generic buttons in wx.lib instead.

Cody