Hi, mates, I am struggling to maintain a scroll bar position after updating textctrl content. Let me show my code firstly:
class MyFrame(rtmgr.MyFrame):
def __init__(self, *args, **kwds):
rtmgr.MyFrame.__init__(self, *args, **kwds)
self.scroll_pos = 0
def updateCtrlMsg(self, msg):
self.scroll_pos = self.text_ctrl_1.GetScrollPos(wx.VERTICAL)
self.text_ctrl_1.SetValue(msg)
self.text_ctrl_1.SetScrollPos(wx.VERTICAL ,self.scroll_pos)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
def main(args=None):
app = MyApp(0)
# Start wxPython main loop
app.MainLoop()
if __name__ == '__main__':
main()
In another thread, I use wx.CallAfter(self.app.frame.updateCtrlMsg, data) to update the content of textctrl.
but one thing confuses me a lot, why the scroll bar of textctrl automatically reset to the top all the time even though i have scrolled down.
could anyone give some suggestions to me to fix it out?
the following gif shows the problems: