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.
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.