[wxPython-users] plese suggest good tutorial for sizers.
Christopher Barker
Chris.Barker at noaa.gov
Fri Jan 5 14:27:19 PST 2007
krishnakant Mane wrote:
> The point here I am trying to address is that some labels will be
> small and some big. for example "name " is a small caption and needs
> small lable and "home-phone" is a big lable. so if I use grid then
> what's the point in having both the lables of same size?
Because people often want their widgets to all line up in columns.
> some times I want to make buttons of different size and I have often
> observed in layout oriented gui (in particular java) that the sizes of
> the controls are mostly not what we desired. this should not happen
> else there is no point using layouts.
Well, be default, buttons are set to be the size they need to be for the
text that is on them, which is usually what you want, unless you want a
bunch all the same same size, in which case you put them in the right
kind of sizer with a wx.EXPAND flag, then they can all size themselves
to what's needed for the longest text. For example -- a bunch of buttons
all lined up on top of each-other, all the same width:
#Create the buttons:
b1 = wx.Button(self, label="button 1")
b2 = wx.Button(self, label="button 2")
b3 = wx.Button(self, label=" a long button 3")
.
.
.
# A vertical box sizer to put them in:
S = wx.BoxSizer(wx.VERTICAL)
# add the buttons:
S.Add(b1, 0, wx.EXPAND)
S.Add(b2, 0, wx.EXPAND)
S.Add(b3, 0, wx.EXPAND)
# the "0" means don't stretch (in this case in the vertical direction
# wx.EXPAND means expand in the horizontal direction
Now this size can be put on a panel, or in another sizer for a more
complex layout.
>> > some times grids make the controls of same size and I don't want it.
>>
>> A GridSizer will make all the controls the same size. A FlexGridSizer
>> will make each column and each row the size it needs to be.
>>
> and what is the logic it uses to decide the size? is it the caption
> or some thing else?
depends on the control -- a button or static text defaults to as big as
it needs to be to hold the text
>> When you Add() a control to a Sizer, you can put a space around it on
>> the side that want -- specify the side with flags: wx.TOP, wx.RIGHT, etc
>> -- or wx.ALL for all. Then the size of that space is specified in pixels
>> by the next parameter.
>>
> so will that in turn actually effect the sizes of the controls?
no, that effects the space around the controls.
> in that case if I can particularly specify where (bwtween which
> columns ) I want to put the gap I can do a lot of good gui I suppose.
> like for example in your example you suggested to leave a column blank
> for the lable-textbox pare. will it not be good to add a gap between
> second and third column so that the first 2 columns can have the first
> pare and then a gap and the second pare of lable-textbox comes in the
> 3rd. and 4th. column after the space?
yes.
> can I also add spacers inside the cells of a grid thus created?
yes.
> I wanted and wont feel it that much complex to code
> and maintain the gui program I create.
It's not too complex to code, and definitely less complex to maintain
than absolute positioning.
> well, so I am now left with 2 options in my particular case. I put a
> vertical box sizer and put horizontal box sizers with controls as I
> wish with spacers around controls or second option is to use a grid
> with gapps in between the second and third columns for seperating
> pares of lable-textboxes. is that right?
That's right. Which you want to do depends on whether you want the
controls in each row to line up with the other rows. If you do use a
FlexGridSizer. If not, the a bunch of horizontal box sizers all stacked
up in a vertical box sizer will do it.
Combined with the other posts, I hope this helps.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list