使用 Sizer 时如何在静态框中添加项目?
我正在使用 wx.Python 并且有一组我想要“包装”在类似于此的静态框中的对象:
但是教程使用位置大小,而我正在使用大小调整器。我很难获取里面的项目:
但它们位于静态框下方。如何使用 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)
I'm using wx.Python and have a group of objects that I want 'wrapped' within a static box similar to this:
However that tutorial uses position sizes, and I'm using sizers instead. I'm having a hard time getting the items inside:
but rather they're below the static box. How do I include the objects within the static box using Sizers and not position?
Here's my code:
# 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Sizer 时,您必须创建一个特定的“静态框 Sizer”,它是一个 Sizer 并包含您要使用的静态框。这是通过以下方式完成的:
这意味着您的 Static Box 需要提前创建,并且是传递给 Sizer 创建的参数。从那时起,Sizer 的行为与常规 Sizer 完全相同。这就是我修复您的代码的结果:
产生以下结果:
When using Sizers, you have to create a specific 'Static Box Sizer' that is a Sizer and contains the Static Box you want to use. This is done by:
This means that your Static Box needs to be created beforehand and is an arguement passed to the creation of the Sizer. From there on, the Sizer behaves exactly like a regular Sizer. This is what I got fixing your code:
Which yields this result: