我正在使用wx.Python并且有一组对象需要“包裹”在类似于此的静态框中:
然而tutorial uses position sizes,而我正在使用sizer。我很难把物品放进去:
但是它们位于静态框之下。如何使用Sizer在静态框中包含对象而不是位置?
这是我的代码:
# Date and Graph Type Selection
self.dateLbl = wx.StaticBox(self, -1, 'Date Range:', size=(240, 140))
self.dategraphSizer = wx.BoxSizer(wx.VERTICAL)
self.dategraphSizer.Add(self.dateLbl, 0, wx.ALL|wx.LEFT, 5)
# Date Range Selection
self.dateSizer = wx.BoxSizer(wx.HORIZONTAL)
self.dateone = wx.TextCtrl(self, -1, style=wx.ALIGN_LEFT)
self.datetwo = wx.TextCtrl(self, -1, style=wx.ALIGN_LEFT)
self.date2Lbl = wx.StaticText(self, -1, "TO")
self.dateSizer.Add(self.dateone, 0, wx.ALL|wx.CENTER, 2)
self.dateSizer.Add(self.date2Lbl, 0, wx.ALL|wx.CENTER, 2)
self.dateSizer.Add(self.datetwo, 0, wx.ALL|wx.CENTER, 2)
# Date Quick Selection Buttons
self.dategraphSizer.Add(self.dateSizer, 0, wx.ALL|wx.CENTER, 5)
self.todayButton = wx.Button(self, -1, 'Today Only')
self.dategraphSizer.Add(self.todayButton, 0, wx.ALL|wx.LEFT, 5)
self.recentButton = wx.Button(self, -1, 'Most Recent Session')
self.dategraphSizer.Add(self.recentButton, 0, wx.ALL|wx.LEFT, 5)
答案 0 :(得分:13)
使用Sizer时,您必须创建一个特定的“Static Box Sizer”,它是一个Sizer并包含您要使用的静态框。这可以通过以下方式完成:
self.foo = wx.StaticBoxSizer(self.box, wx.ORIENT)
这意味着您的静态框需要事先创建,并且是传递给Sizer创建的争论。从那时起,Sizer的行为与常规的Sizer完全相同。这就是我修复代码的原因:
# Date and Graph Type Selection
self.dateLbl = wx.StaticBox(self, -1, 'Date Range:', size=(240, 140))
self.dategraphSizer = wx.StaticBoxSizer(self.dateLbl, wx.VERTICAL)
#self.dategraphSizer.Add(self.dateLbl, 0, wx.ALL|wx.LEFT, 5) NOTE THIS ISN'T NEEDED ANYMORE
# Date Range Selection
self.dateSizer = wx.BoxSizer(wx.HORIZONTAL)
self.dateone = wx.TextCtrl(self, -1, style=wx.ALIGN_LEFT)
self.datetwo = wx.TextCtrl(self, -1, style=wx.ALIGN_LEFT)
self.date2Lbl = wx.StaticText(self, -1, "TO")
self.dateSizer.Add(self.dateone, 0, wx.ALL|wx.CENTER, 2)
self.dateSizer.Add(self.date2Lbl, 0, wx.ALL|wx.CENTER, 2)
self.dateSizer.Add(self.datetwo, 0, wx.ALL|wx.CENTER, 2)
# Date Quick Selection Buttons
self.dategraphSizer.Add(self.dateSizer, 0, wx.ALL|wx.CENTER, 5)
self.todayButton = wx.Button(self, -1, 'Today Only')
self.dategraphSizer.Add(self.todayButton, 0, wx.ALL|wx.LEFT, 5)
self.recentButton = wx.Button(self, -1, 'Most Recent Session')
self.dategraphSizer.Add(self.recentButton, 0, wx.ALL|wx.LEFT, 5)
产生这个结果: