【问题标题】:How can I fix the scroll bug when using Windows rich edit controls in wxpython?在 wxpython 中使用 Windows 富编辑控件时如何修复滚动错误?
【发布时间】:2010-05-16 22:59:34
【问题描述】:

当在 windows 中使用 wx.TextCtl 和 wx.TE_RICH2 选项时,我在使用 AppendText 函数时自动滚动出现这个奇怪的错误。它滚动以使所有文本都位于可见区域上方,这不是很有用的行为。

我尝试在附加文本后添加对 ScrollLines(-1) 的调用 - 这确实将其滚动到正确的位置 - 但这会导致窗口在自动滚动时闪烁。所以我正在寻找另一种自动滚动到底部的方法。

到目前为止,我的解决方案是绕过 AppendText 函数自动滚动并实现我自己的,如下所示:

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)

有没有更好的办法?

【问题讨论】:

    标签: python user-interface wxpython wxwidgets textctrl


    【解决方案1】:

    你已经接近了。

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

    【讨论】:

      【解决方案2】:

      在 wxpython 中使用 Windows 富编辑控件时,您可以使用以下方法修复滚动错误:

      textctrl.MoveEnd()
      textctrl.WriteText(text)
      

      【讨论】:

      • 虽然这段代码可以回答问题,但最好解释一下如何解决问题,并提供代码作为示例或参考。仅代码的答案可能会令人困惑且缺乏上下文。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-09
      • 2019-11-05
      相关资源
      最近更新 更多