Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static text vertical alignment with wxPython

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)?

Text is not vertically aligned in Search Panel

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()
like image 929
Mor Sagmon Avatar asked Sep 17 '25 14:09

Mor Sagmon


1 Answers

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)
like image 80
Simon Avatar answered Sep 22 '25 09:09

Simon