如何滚动到 wxTextCtrl 的底部并重绘屏幕

How to scroll to the bottom of a wxTextCtrl and redraw screen

我有一个 wxTextCtrl,其中包含许多启用了滚动条的文本行。在一个事件中,我想滚动到控件的末尾并重绘控件。

这是我的:

    def event_scroll_to_end(self, event):
        self.m_textCtrl1.SetScrollPos(
            wx.VERTICAL,
            self.m_textCtrl1.GetScrollRange(wx.VERTICAL))
        event.Skip()

这会滚动到末尾并且 updates/redraws 滚动条本身,但它不会更新 textCtrl,它仍然显示滚动到其当前位置。

我怎样才能实际滚动 textCtrl 以便内容滚动到末尾,如滚动条所示?

我怀疑你需要设置插入点,如果你想定位在文本的末尾即

def event_scroll_to_end(self, event):
    self.m_textCtrl1.SetScrollPos(
        wx.VERTICAL,
        self.m_textCtrl1.GetScrollRange(wx.VERTICAL))
    self.m_textCtrl1.SetInsertionPoint(-1)
    event.Skip()

使用 SetInsertionPoint(0) 将您自己定位在文本的开头。

ShowPosition函数可用于通过显示缓冲区的最后位置滚动到末尾。

    def event_scroll_to_end(self, event):
        self.m_textCtrl3.ShowPosition(self.m_textCtrl3.GetLastPosition())
        event.Skip()

我也一直在为此苦苦挣扎。 最后,以下对我有用:

    mywindow.SetInsertionPoint(-1)
    mywindow.ShowPosition(mywindow.GetLastPosition())
    mywindow.Refresh()
    mywindow.Update()