I am just getting started with wxPython. I have the following code:
import wx
class SASFrame(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
groupPanel = wx.Panel(self)
st = wx.StaticText(groupPanel, -1, "Which characteristics would you like to group by?")
cbAge = wx.CheckBox(groupPanel, -1, "Age")
cbMarket = wx.CheckBox(groupPanel,-1, "Market")
groupSizer = wx.BoxSizer(wx.VERTICAL)
groupSizer.AddMany([st,cbAge, cbMarket])
groupPanel.SetSizer(groupSizer)
summaryPanel = wx.Panel(self)
st2 = wx.StaticText(summaryPanel, -1, "What would you like to summarize?")
cbPremiums = wx.CheckBox(summaryPanel,-1, "Premiums")
cbClaims = wx.CheckBox(summaryPanel,-1, "Claims")
summarySizer = wx.BoxSizer(wx.VERTICAL)
summarySizer.AddMany([st2,cbPremiums,cbClaims])
summaryPanel.SetSizer(summarySizer)
frameSizer = wx.BoxSizer(wx.VERTICAL)
frameSizer.Add(groupPanel,1,wx.EXPAND)
frameSizer.Add(summaryPanel,1,wx.EXPAND)
self.SetSizer(frameSizer)
class SASApp(wx.App):
def __init__(self):
wx.App.__init__(self)
def OnInit(self):
self.frame = SASFrame(parent=None,id=-1,title="HCRFM Custom Report Generator")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = SASApp()
app.MainLoop()
if __name__ == '__main__':
main()
When I resize the window so that it is really small, it looks like this:
overlap
How can I prevent this overlapping? Also, how can I make it so the the user cannot make the window small enough to cut off the text going horizontally? I am not sure if I should worry about the latter.
2 Answers 2
Just edit your line to this:
self.SetSizerAndFit(frameSizer)
It is going to behave exactly as you would expect. It will layout your widgets to minimum size window (add borders or spaces if / where you need it) and it will never allow smaller window than that. More information in wx docs: http://www.wxpython.org/docs/api/wx.Window-class.html#SetSizerAndFit
Comments
The way I do is to determine and fix the minimum size of the window that prevents unwanted hiding of widgets. I use wx.Window method:
SetMinSize((x,y))
wx.Window has another alternative method:
SetSizeHintsSz(self, minSize, maxSize=DefaultSize, incSize=DefaultSize)
Allows specification of minimum and maximum window sizes, and window size increments. If a pair of values is not set (or set to -1), the default values will be used. If this function is called, the user will not be able to size the window outside the given bounds (if it is a top-level window.) Sizers will also inspect the minimum window size and will use that value if set when calculating layout.
The resizing increments are only significant under Motif or Xt.