Aligning statictext and textctrl

831 views
Skip to first unread message

Steven

unread,
Oct 10, 2011, 8:30:03 PM10/10/11
to wx-users
I'm just starting to use wxWidgets/wxPython and I've hit a snag. I
have 4 widgets arranged like this

StaticText TextCtrl
StaticText TextCtrl

And I want the StaticText to all be aligned to the left, and TextCtrl
aligned to the right. This is what I have now

vbox = wx.BoxSizer(wx.VERTICAL)

hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox.Add(hbox)
hbox.Add(wx.StaticText(panel, label="Label1: "))
self._namebox = wx.TextCtrl(panel)
hbox.Add(self._namebox, flag=wx.ALIGN_RIGHT | wx.RIGHT |
wx.LEFT,
border=10)

hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox.Add(hbox)
hbox.Add(wx.StaticText(panel, label="Longer Label2: "))
self._filenamebox = wx.TextCtrl(panel)
hbox.Add(self._filenamebox, flag=wx.ALIGN_RIGHT | wx.RIGHT |
wx.LEFT,
border=10)

But when I run this the TextLabel is still aligned to the left. What
am I doing wrong?

Gadget/Steve

unread,
Oct 11, 2011, 6:29:23 AM10/11/11
to wx-u...@googlegroups.com
You are missing out the proportion flag from the Add commands, change
them all to read, (initially), Add(self.whatever,1, ALIGN_ ...

Gadget/Steve

Vadim Zeitlin

unread,
Oct 11, 2011, 6:38:58 AM10/11/11
to wx-u...@googlegroups.com
On Mon, 10 Oct 2011 17:30:03 -0700 (PDT) Steven <si...@siyuz.net> wrote:

S> I'm just starting to use wxWidgets/wxPython and I've hit a snag. I
S> have 4 widgets arranged like this
S>
S> StaticText TextCtrl
S> StaticText TextCtrl

In addition to the other reply, notice that usually you'd use a 2 column
wxFlexGridSizer instead of 2 box sizers to make this layout to ensure that
the text controls are aligned with each other.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Reply all
Reply to author
Forward
0 new messages