문제

When using wx.TextCtl with the wx.TE_RICH2 option in windows, I get this strange bug with the auto-scroll when using the AppendText function. It scrolls so that all the text is above the visible area, which isn't very useful behaviour.

I tried just adding a call to ScrollLines(-1) after appending the text - which does scroll it to the correct position - but this can lead to the window flashing when it auto-scrolls. So I'm looking for another way to automatically scroll to the bottom.

So far, my solution is to bypass the AppendText functions auto-scroll and implement my own, like this:

def append_text(textctrl, text):
    before_number_of_lines = textctrl.GetNumberOfLines()

    textctrl.SetInsertionPointEnd()
    textctrl.WriteText(text)

    after_number_of_lines = textctrl.GetNumberOfLines()
    textctrl.ScrollLines(before_number_of_lines - after_number_of_lines + 1)

Is there a better way?

도움이 되었습니까?

해결책

You're close.

    textctrl.SetInsertionPointEnd()
    textctrl.WriteText(licence)
    textctrl.SetInsertionPointEnd()

다른 팁

You can use the following to fix the scroll bug when using Windows rich edit controls in wxpython:

textctrl.MoveEnd()
textctrl.WriteText(text)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top