Reputation: 422
how it going?
I'm trying to align two wx.StaticText inside a horizontal box, which is inside a vertical wx.StaticBoxSizer. See for yourself. I guess the code says what I'm trying to do.
Thanks!
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self)
left = wx.StaticText(self, -1, 'left', style=wx.ALIGN_LEFT)
right = wx.StaticText(self, -1, 'right', style=wx.ALIGN_RIGHT)
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left)
hBox.Add(right)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()
Upvotes: 0
Views: 648
Reputation: 22458
Ever since the removal of wx.ALIGN_LEFT
and wx.ALIGN_RIGHT
in horizontal boxsizers and the introduction of:
wx._core.wxAssertionError: C++ assertion "!(flags & wxALIGN_RIGHT)" failed at /tmp/pip-install-8ko13ycp/wxpython/ext/wxWidgets/src/common/sizer.cpp(2168) in DoInsert(): Horizontal alignment flags are ignored in horizontal sizers
,
it's an issue.
Another option is to use the spacing
in the sizer instruction to the Left and/or Right. e.g.
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self, "Test")
left = wx.StaticText(self, -1, 'left')
right = wx.StaticText(self, -1, 'right')
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left, 0, wx.RIGHT, 100)
hBox.Add(right, 0, wx.LEFT, 100)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()
Upvotes: 1
Reputation: 422
It seems I have to specify a size
to make the aligment work!
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self)
left = wx.StaticText(self, -1, 'left', size=(175, 15), style=wx.ALIGN_LEFT)
right = wx.StaticText(self, -1, 'right', size=(25, 15))
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left)
hBox.Add(right)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()
Upvotes: 0