Filling the available space with a column in the GridBagSizer

I am trying to create a dialogue in which there are several long descriptions, each of which is accompanied by a short question with answers using the switch. I set my controls using GridBagSizer( wxWidgets docs , wxPython docs ), in which a long description covers all three columns, and the answers to the question and two radio buttons are in their own columns.

enter image description here

, , flag=wx.EXPAND StaticText . ; , , .

import wx

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

        sizer = wx.GridBagSizer(5, 5)
        sizer.SetEmptyCellSize((0,0))
        sizer.AddGrowableCol(0)

        for i in range(5):
            description = wx.StaticText(self, -1, "This is a long description \
that may span several lines. Filler filler filler filler filler. More filler \
filler filler filler filler.")
            description.Wrap(500)

            question = wx.StaticText(self, -1, "Are you sure?")
            yes = wx.RadioButton(self, -1, "Yes", style = wx.RB_GROUP)
            no = wx.RadioButton(self, -1, "No")

            sizer.Add(description, (i*3, 0), (1, 3))
            sizer.Add(question, (i*3+1, 0), flag=wx.EXPAND)
            sizer.Add(yes, (i*3+1, 1))
            sizer.Add(no, (i*3+1, 2))

        self.SetSizerAndFit(sizer)
        self.Show()


app = wx.App(False)
dialog = MyDialog(None)
app.MainLoop()

wx.EXPAND, . wx.ALIGN_RIGHT , , , "" , , .

- ? GridBagSizer expand, , ? , ? .

+3
2

, wx.Sizer.AddStretchSpacer(), . http://wxpython.org/docs/api/wx.Sizer-class.html#AddStretchSpacer

, StretchSpacers, -, wx.GridBagSizer

sizer.Add(description, (i*3, 0), (1, 3))
sizer.Add(question, (i*3+1, 0), flag=wx.EXPAND)
sizer.AddStretchSpacer((i*3+1,1))
sizer.Add(yes, (i*3+1, 2), flag=wx.ALIGN_RIGHT)
sizer.Add(no, (i*3+1, 3))

, "" . , . , , "" ( 0!). , "" . , , , soltuion.

wx.BoxSizer . ( , ). , @Mike Discoll, wx.BoxSizers

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

        sizer = wx.BoxSizer(wx.VERTICAL)

        for i in range(5):
            description = wx.StaticText(self, -1, "This is a long description \
that may span several lines. Filler filler filler filler filler. More filler \
filler filler filler filler.")
            description.Wrap(500)

            questionSizer = wx.BoxSizer(wx.HORIZONTAL)
            question = wx.StaticText(self, -1, "Are you sure?")
            yes = wx.RadioButton(self, -1, "Yes", style = wx.RB_GROUP)
            no = wx.RadioButton(self, -1, "No")

            sizer.Add(description)
            questionSizer.Add(question)
            questionSizer.AddStretchSpacer()
            questionSizer.Add(yes)
            questionSizer.Add(no)
            sizer.Add(questionSizer, flag=wx.EXPAND)

        self.SetSizerAndFit(sizer)
        self.Show()

, , :

Stretch Spacer and wx.BoxSizer

, questionSizer wx.EXPAND, , . sizer.Add() wx.EXPAND, (.. ). wx.Expand sizer (, - , , 500 )

, , .

--- EDIT ---

, ( 500 ), - self.SetSizerAndFit() :

Small Description without Min Size

, , sizer, minium.

[...]
width = 500 #the desired minimum width
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.SetMinSize((width,1)) #ensures sizer will be minimum width
"""NOTE: the minimum size gets recalculated when new items are added.
i.e. if height exceeds 1 pixel or if width exceeds wdith, the sizer
will recalculate the minimum size"""


for i in range(5):
    description = wx.StaticText(self, -1, "Short Description") #description is less than 500 pixels, Wrap() will have no effect.
    description.Wrap(width)
[...]

:

Small Descriptio with Min Size

+2

, SetSizerAndFit(). SetSizer(). . BoxSizer, .

+1

All Articles