Reputation: 5991
Seems like this would be simple but I can't find a good way to do this. All I'm looking for is have a nice centered title for a larger multi-line TextCtrl widget I have in a wxPython frame. There doesn't seem to be a way to do this with the actual TextCtrl properties. So I have tried to do this StaticText label, but I can't seem to get to line up nicely with the TextCtrl control. Right now I have them in two different BoxSizer(wx.HORIZONTAL) with a Button control and StaticText. Maybe that is the best I can do with these in wxPython?
Upvotes: 2
Views: 2760
Reputation: 3113
I do something similiar in my code. I think you want to set the "wx.ALIGN_CENTER_HORIZONTAL" flag when you add the StaticText to the sizer. That will center the StaticText inside of it's cell. By setting wx.EXPAND on the TextCtrl, we're saying it should be the maximum width of the sizer, therefore the StaticText will be centered relative to the TextCtrl.
import wx
ID_SUBMIT = wx.NewId()
...
sizer = wx.BoxSizer(wx.VERTICAL)
centeredLabel = wx.StaticText(self, -1, 'Centered Label')
sizer.Add(centeredLabel, flag=wx.ALIGN_CENTER_HORIZONTAL)
mlTextCtrl = wx.TextCtrl(self, style = wx.TE_MULTILINE)
sizer.Add(mlTextCtrl, flag=wx.EXPAND)
submitButton = wx.Button(self, ID_SUBMIT,'Submit')
sizer.Add(submitButton, flag=wx.ALIGN_RIGHT)
...
Upvotes: 4