Search code examples
wxpython

TextCtrl: How to set text position?


I have a TextCtrl with a scroll bar and I want the first lines of my text to appear in my TextCtrl. But instead the last lines of the text appear. When I set my scrollbar position to the top of my TextCtrl, then still the last lines of the text appear. Any idea how to solve this problem?

f = open(path, 'r')
TC = wx.TextCtrl(self, -1, '',
                    size=(400, 200), pos=(10,140), style=wx.TE_RICH2|wx.TE_MULTILINE|wx.VSCROLL)
for line in f.readlines():
    TC.write(line)
f.close
TC.SetEditable(False)
TC.SetScrollPos(wx.VERTICAL,0)
TC.Refresh()

Solution

  • I believe the call you want is SetInsertionPoint(0).