wxPython:嵌套 GridBagSizer 不跨越?

发布于 2024-11-19 05:40:23 字数 1231 浏览 5 评论 0原文

我在现有的 GridBagSizer (sizer) 中有一个 GridBagSizer (folderBagSizer)...现在我尝试用一​​些标签填充嵌套的 sizer (folderBagSizer)。他们出现在尺寸测量器下面......?

# Create static box
self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract", 
    size=(100,100))
folderBoxSizer = wx.GridBagSizer(4, 9)
folderBoxSizer.Add(self.sb_ExtractOptions, pos=(0,0), span=(1,4), 
    flag=wx.EXPAND, border=10)

# Create the options
label_OptionsCreated = wx.StaticText(panel, label="Created:")
label_OptionsInserted = wx.StaticText(panel, label="Inserted:")
label_OptionsModified = wx.StaticText(panel, label="Modified:")

# Add them to the sizer (folderBoxSizer)
folderBoxSizer.Add(label_OptionsCreated, pos=(1, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsInserted, pos=(2, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsModified, pos=(3, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)

folderBoxSizer.AddGrowableCol(2)
sizer.Add(folderBoxSizer, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)


sizer.AddGrowableCol(2)
panel.SetSizer(sizer)

提前致谢。 :)

I've g0t a GridBagSizer (folderBagSizer)within an existing GridBagSizer (sizer)... now I am trying to populate the nested sizer (folderBagSizer) with some labels. They are showing up UNDER the sizers...?

# Create static box
self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract", 
    size=(100,100))
folderBoxSizer = wx.GridBagSizer(4, 9)
folderBoxSizer.Add(self.sb_ExtractOptions, pos=(0,0), span=(1,4), 
    flag=wx.EXPAND, border=10)

# Create the options
label_OptionsCreated = wx.StaticText(panel, label="Created:")
label_OptionsInserted = wx.StaticText(panel, label="Inserted:")
label_OptionsModified = wx.StaticText(panel, label="Modified:")

# Add them to the sizer (folderBoxSizer)
folderBoxSizer.Add(label_OptionsCreated, pos=(1, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsInserted, pos=(2, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsModified, pos=(3, 0), flag=wx.LEFT|
    wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)

folderBoxSizer.AddGrowableCol(2)
sizer.Add(folderBoxSizer, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)


sizer.AddGrowableCol(2)
panel.SetSizer(sizer)

Thanks in advance. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心房敞 2024-11-26 05:40:23

想通了,当然,完全是菜鸟逻辑问题。

    # Create static box
    self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract", size=(100,100))
    sbs_ExtractOptions = wx.StaticBoxSizer(self.sb_ExtractOptions, wx.VERTICAL)
    OptionBoxSizer = wx.GridBagSizer(4, 9)

    # Create the options
    logicList = ['<', '<=', '=', '>', '>=']

    sizerIndexX = 0

    # Created
    label_OptionsCreated = wx.StaticText(panel, label="Created:")
    combo_LogicalCreated = wx.ComboBox(panel, 1, "", (25, 25), (60, 25), logicList, wx.CB_DROPDOWN)
    combo_LogicalCreated.Select(1)
    self.tc_DaysAgoCreated = wx.TextCtrl(panel)
    label_DaysAgoCreated = wx.StaticText(panel, label="days ago")
    # Add them to the sizer (optionBoxSizer)
    OptionBoxSizer.Add(label_OptionsCreated, pos=(sizerIndexX, 0), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border=0)
    OptionBoxSizer.Add(combo_LogicalCreated, pos=(sizerIndexX,1), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=1)
    OptionBoxSizer.Add(self.tc_DaysAgoCreated, pos=(sizerIndexX, 2), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)
    OptionBoxSizer.Add(label_DaysAgoCreated, pos=(sizerIndexX,3), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)

<snip>

   sbs_ExtractOptions.Add(OptionBoxSizer, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)
    sizer.Add(sbs_ExtractOptions, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)

我最初将静态框的大小调整器添加到错误的大小调整器中 - 它需要工作的方式是:

  1. 创建静态框 (self.sb_ExtractOptions)
  2. 创建
    sizer 将位于其中,在本例中为 StaticBoxSizer。
    (sbs_ExtractOptions)
  3. 为要布局的对象创建网格
    在 sizer (OptionBoxSizer) 中
  4. 创建 GUI 元素并添加
    将它们添加到 OptionBoxSizer
  5. 将 OptionBoxSizer 添加到
    StaticBoxSizer(即将步骤 4 中所做的操作添加到步骤 2 中)
  6. 添加
    将 StaticBoxSizer 添加到面板的主大小调整器(在本例中为大小调整器)
  7. 喝一杯啤酒,或 5。然后像我一样庆祝新课程
    非常注意你在做什么!

Figured it out, and of course, total noob logic problem.

    # Create static box
    self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract", size=(100,100))
    sbs_ExtractOptions = wx.StaticBoxSizer(self.sb_ExtractOptions, wx.VERTICAL)
    OptionBoxSizer = wx.GridBagSizer(4, 9)

    # Create the options
    logicList = ['<', '<=', '=', '>', '>=']

    sizerIndexX = 0

    # Created
    label_OptionsCreated = wx.StaticText(panel, label="Created:")
    combo_LogicalCreated = wx.ComboBox(panel, 1, "", (25, 25), (60, 25), logicList, wx.CB_DROPDOWN)
    combo_LogicalCreated.Select(1)
    self.tc_DaysAgoCreated = wx.TextCtrl(panel)
    label_DaysAgoCreated = wx.StaticText(panel, label="days ago")
    # Add them to the sizer (optionBoxSizer)
    OptionBoxSizer.Add(label_OptionsCreated, pos=(sizerIndexX, 0), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border=0)
    OptionBoxSizer.Add(combo_LogicalCreated, pos=(sizerIndexX,1), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=1)
    OptionBoxSizer.Add(self.tc_DaysAgoCreated, pos=(sizerIndexX, 2), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)
    OptionBoxSizer.Add(label_DaysAgoCreated, pos=(sizerIndexX,3), flag=wx.ALL|
        wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)

<snip>

   sbs_ExtractOptions.Add(OptionBoxSizer, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)
    sizer.Add(sbs_ExtractOptions, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)

I was adding the sizer for the static box to the wrong sizer initially -- the way it needs to work is to:

  1. Create the static box (self.sb_ExtractOptions)
  2. Create the
    sizer that will live within it, in this case a StaticBoxSizer.
    (sbs_ExtractOptions)
  3. Create the grid for my objects to layout
    within the sizer (OptionBoxSizer)
  4. Create GUI elements and add
    them to OptionBoxSizer
  5. Add the OptionBoxSizer to the
    StaticBoxSizer (i.e. add what you did in step 4 to step 2)
  6. Add
    the StaticBoxSizer to the panel's main sizer (sizer, in this case)
  7. Drink a beer, or 5. And celebrate your new lesson like I did in
    paying freaking attention to what you are doing!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文