使用 Sizer 时如何在静态框中添加项目?

发布于 2024-11-26 18:54:55 字数 1434 浏览 3 评论 0原文

我正在使用 wx.Python 并且有一组我想要“包装”在类似于此的静态框中的对象:

enter此处的图像描述

但是教程使用位置大小,而我正在使用大小调整器。我很难获取里面的项目:

在此处输入图像描述

但它们位于静态框下方。如何使用 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:

enter image description here

However that tutorial uses position sizes, and I'm using sizers instead. I'm having a hard time getting the items inside:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有一腔孤勇 2024-12-03 18:54:55

使用 Sizer 时,您必须创建一个特定的“静态框 Sizer”,它是一个 Sizer 并包含您要使用的静态框。这是通过以下方式完成的:

self.foo = wx.StaticBoxSizer(self.box, wx.ORIENT)

这意味着您的 Static Box 需要提前创建,并且是传递给 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)

产生以下结果:

在此处输入图像描述

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:

self.foo = wx.StaticBoxSizer(self.box, wx.ORIENT)

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:

    # 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)

Which yields this result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文