Nate
Nate

Reputation: 19442

Centering wx.TextCtrl?

I'm having difficulties centering the text within a wx.TextCtrl (as shown in the photoshopped illustration below). -- For some reason, it always prints LEFT aligned, instead of CENTERED.

Illustration of desired output

Could someone please point me to the proper "styles" OR tell me what I'm doing wrong?

import wx

class SimplePanel(wx.Panel):

    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
        myTextCtrl = wx.TextCtrl(self, -1,
                                 style=wx.TE_CENTRE,
                                 size=(100, -1), pos=(10, 10))

if __name__ == '__main__':
    app = wx.App()

    frame = wx.Frame(None, -1, 'Simple Panel') 
    myPanel = SimplePanel(frame, -1)
    frame.Show()

    app.MainLoop()

Upvotes: 4

Views: 3684

Answers (2)

Nate
Nate

Reputation: 19442

This seems to work fine on Windows but I was using both OSX and Windows for development and wx.TE_CENTRE does not appear to work on OSX. This was defect was reported many years ago (http://trac.wxwidgets.org/ticket/10010).

Upvotes: 2

Jake
Jake

Reputation: 2625

(Edited after clarification)

There was a bug once in wxPython which broke TE_CENTRE for some OSes:

http://wxpython-users.1045709.n5.nabble.com/ANN-wxPython-2-8-9-1-td2367679.html

Try updating to the latest version perhaps.

Upvotes: 1

Related Questions