Reputation: 1035
I'm designing a form with wxPython. Note the search panel in the picture: the "Search By: " label, the combo box nest to it and the search control - all have their text aligned to the top. How can I align them all to be in the middle (vertically)?
This is the Search PAnel code:
class TopNavigationPanel(wx.Panel):
def __init__(self, parentPanel):
"""Constructor"""
wx.Panel.__init__(self, parent=parentPanel, id=-1)
self.SetBackgroundColour("red")
self.searchByLbl = wx.StaticText(self, label="Search By: ", style=wx.ALIGN_RIGHT, size=(80, -1))
cat = ["Author", "Title", "ISBN", "Publisher"]
categories = wx.ComboBox(self, value="Author", choices=cat, size=(100, -1))
self.search = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER, size=(160, -1))
self.search.Bind(wx.EVT_TEXT_ENTER, parentPanel.onSearch)
navigationSizer = wx.BoxSizer(wx.HORIZONTAL)
navigationSizer.AddSpacer(50)
navigationSizer.Add(self.searchByLbl, 0, wx.EXPAND, 0)
navigationSizer.Add(categories, 0, wx.EXPAND, 0)
navigationSizer.Add(self.search, 0, wx.EXPAND, 0)
navigationSizer.AddSpacer(500)
self.SetSizer(navigationSizer)
self.Fit()
Upvotes: 4
Views: 4372
Reputation: 39
You can use ALIGN_CENTER_VERTICAL.
In the snippet bellow I have the text vertically aligned with the button in an horizontal box sizer:
dbBox = wx.BoxSizer(wx.HORIZONTAL)
updateBtn = wx.Button(dbFrm, label = "Update")
dbBox.Add(updateBtn, 0, wx.LEFT | wx.RIGHT, 5)
self.dateLbl = wx.StaticText(dbFrm, label = "Never updated")
dbBox.Add(self.dateLbl, 1, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
Upvotes: 3
Reputation: 1035
OK, found the way to do it. Posting here for others.
We can pad each control as we add it to the sizer from either direction. Here I'm padding 7 from the top:
navigationSizer.Add(self.searchByLbl, 0, wx.EXPAND | wx.TOP, 7)
Upvotes: 0