Reputation: 480
I am trying to center the text inside a TextCtrl. Many solutions to other similar questions rely on using ALIGN_CENTER_VERTICAL
however I cannot do this as I want my text box to be larger than the font height.
This is what I am trying now:
self.name_tb = wx.TextCtrl(self.showing_panel, style=wx.BORDER_NONE | wx.TE_CENTRE)
self.showing_sizer.Add(self.name_tb, 1, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=3)
self.name_tb.SetMinSize((-1, height)) # height > font height
Desired outcome is that the text and the cursor is aligned vertically centered.
Edit:
Code and Screenshot of runnable code
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.SetSize((400, 200))
self.SetTitle("Centre Text Vertically")
self.panel = wx.Panel(self, wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
self.text_ctrl = wx.TextCtrl(self.panel, wx.ID_ANY, "", style=wx.TE_CENTRE)
self.text_ctrl.SetMinSize((150, 50))
sizer.Add(self.text_ctrl, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, 40)
self.panel.SetSizer(sizer)
self.Layout()
wx.CallAfter(self.displayText)
def displayText(self):
self.text_ctrl.SetValue("Text Text Text")
self.text_ctrl.SetInsertionPointEnd()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
It seems like this is only an issue on Mac. Any ideas?
Upvotes: 0
Views: 97