wxPython BoxSizer

J

Jamie McQuay

Simple question, i just can't make it work.

I need to center a StaticText component in its parent (Panel). I want
to do this with BoxSizer(s).

if i use:
box = wx.BoxSizer(wx.VERTICAL) #or wx.HORIZONTAL
box.Add(myText,0,wx.ALIGN_CENTER)
parentPanel.Sizer = box

i can get it to center either vertically or horizontally, but not both
(i.e. the center). I've tried myText.CenterOnParent but i need to
handle to Size event to move the text when the panel is resized and i
don't want to have to do this.

thanks,
Jamie
 
M

Mike Driscoll

Hi Jamie,

Simple question, i just can't make it work.

I need to center a StaticText component in its parent (Panel).  I want
to do this with BoxSizer(s).

if i use:
box = wx.BoxSizer(wx.VERTICAL)   #or wx.HORIZONTAL
box.Add(myText,0,wx.ALIGN_CENTER)
parentPanel.Sizer = box

i can get it to center either vertically or horizontally, but not both
(i.e. the center).  I've tried myText.CenterOnParent but i need to
handle to Size event to move the text when the panel is resized and i
don't want to have to do this.

thanks,
Jamie

Try the style=wx.CENTER like this:

box.Add(myText,0,wx.CENTER)

FYI: There's a great wxPython mailing list too. Check it out here:
http://wxpython.org/maillist.php

Mike
 
J

Jamie McQuay

Try the style=wx.CENTER like this:

box.Add(myText,0,wx.CENTER)

tried but i still get the same result. The text is either at the top
of the panel (centered) or in the middle (on the left side). If i
manually call CenterOnParent when the panel is resized it goes to the
center but i want to get the sizers to work correctly for this.
FYI: There's a great wxPython mailing list too. Check it out here:http://wxpython.org/maillist.php

thanks, i will take a look.

Jamie
 
J

Jamie McQuay

thanks, i will take a look.

Here is the answer i got from the mailing list (and it works)

Try adding a spacer on both sides of text.

i.e)
box.AddStretchSpacer()
box.Add(myText, 0, wx.ALIGN_CENTER)
box.AddStretchSpacer()

jamie
 
M

Mike Driscoll

Here is the answer i got from the mailing list (and it works)

Try adding a spacer on both sides of text.

i.e)
box.AddStretchSpacer()
box.Add(myText, 0, wx.ALIGN_CENTER)
box.AddStretchSpacer()

jamie

Yeah...I saw that on the wx list. I either had forgotten about that
method or never knew it existed. The wx.CENTER style should have
worked. Robin Dunn might explain it later. You can learn a lot from
the guys (and girls) on that list though.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,293
Latest member
Hue Tran

Latest Threads

Top