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)

提前致谢。:)

4

1 回答 1

0

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

    # 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 添加到面板的主 sizer(在本例中为 sizer)
  7. 喝一杯啤酒,或者 5 杯。然后像我一样庆祝你的 新课,全神贯注于你在做什么!
于 2011-07-13T14:35:05.167 回答