In the following code, the Frame ends up being too small, one of the panels
inside it is shorter than its MinSize. How do I go about correcting this?
The panel's MinSize is (203, 121) but its size is (361, 110)
Thanks.
import wx
class MainFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.MINIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU
wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN
wx.Frame.__init__(self, *args, **kwds)
self.SetTitle("The Title")
self.mainStatusBar = self.CreateStatusBar(number=1)
#Main background area
self.panelMain = wx.Panel(self, wx.ID_ANY)
self.sizerMain = wx.BoxSizer(wx.VERTICAL)
self.panelMain.SetSizer(self.sizerMain)
self.__SetUpToolbar()
#Tabs
self.tabs = wx.Notebook(parent=self.panelMain, id=wx.ID_ANY,
style=wx.NB_TOP)
self.sizerMain.Add(item=self.tabs, proportion=1,
flag=wx.EXPAND | wx.ALL, border=5)
#Tab1
self.tabMain = wx.Panel(parent=self.tabs, id=wx.ID_ANY)
self.sizerTabMain = wx.BoxSizer(wx.VERTICAL)
self.tabMain.SetSizer(self.sizerTabMain)
self.tabMainInner = wx.Panel(parent=self.tabMain, id=wx.ID_ANY)
self.sizerTabMain.Add(item=self.tabMainInner, proportion=1,
flag=wx.EXPAND | wx.ALL, border=10)
self.tabMainBox = wx.StaticBox(parent=self.tabMainInner,
id=wx.ID_ANY, label="Database")
self.sizerTabMainInner = wx.StaticBoxSizer(box=self.tabMainBox,
orient=wx.VERTICAL)
self.tabMainInner.SetSizer(self.sizerTabMainInner)
self.tabs.AddPage(page=self.tabMain, text="General", select=True)
#Tab1 - Line 1
self.staticTextLine1 = \
wx.StaticText(parent=self.tabMainInner, id=wx.ID_ANY,
label="This is a long string with lots of words.")
self.sizerTabMainInner.Add(item=self.staticTextLine1,
proportion=0,
flag=wx.TOP | wx.BOTTOM | wx.LEFT,
border=10)
#Tab1 - Line 2
self.staticTextLine2 = \
wx.StaticText(parent = self.tabMainInner, id = wx.ID_ANY,
label = "Line 2")
self.sizerTabMainInner.Add(item=self.staticTextLine2,
proportion=0,
flag=wx.TOP | wx.BOTTOM | wx.LEFT,
border=10)
#Tab1 - The Button
self.theButton = wx.Button(parent=self.tabMainInner, id=wx.ID_ANY,
label="The Button")
self.sizerTabMainInner.Add(item=self.theButton, proportion=0,
flag=wx.ALIGN_RIGHT | wx.LEFT |
wx.RIGHT | wx.BOTTOM,
border=10)
#Sizing
tabMainInnerSize = self.tabMainInner.GetBestSize()
self.tabMainInner.SetMinSize(tabMainInnerSize)
print "tabMainInner MinSize set to:", tabMainInnerSize
self.Layout()
self.Fit()
self.Refresh()
print "tabMainInner Size at end:", self.tabMainInner.GetSize()
print "tabMainInner MinSize at end:", self.tabMainInner.GetMinSize()
def __OnStatus(self, evt):
pass
def __SetUpToolbar(self):
self.__TB_ID_STATUS = 10
self.__tb = self.CreateToolBar(style=wx.TB_HORIZONTAL | wx.NO_BORDER
wx.TB_FLAT)
wx.ART_FILE_SAVE
tsize = (32, 32)
self.__tb.SetToolBitmapSize(tsize)
statusBmp = wx.ArtProvider_GetBitmap(wx.ART_HELP, wx.ART_OTHER,
tsize)
self.__tb.AddSimpleTool(id=self.__TB_ID_STATUS, bitmap=statusBmp,
shortHelpString="Status", longHelpString="Get the status of the radio
network.")
self.Bind(wx.EVT_TOOL, self.__OnStatus, id=self.__TB_ID_STATUS)
self.__tb.Realize()
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame(None, wx.ID_ANY)
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(False) #False prevents wxWidgets from using own console
app.MainLoop()