如何从wxPython中的wx.TextCtrl控件获取滚动位置/范围 [英] How do I get the scroll position / range from a wx.TextCtrl control in wxPython

查看:399
本文介绍了如何从wxPython中的wx.TextCtrl控件获取滚动位置/范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的日志记录应用程序(用wxPython编写),它从我们正在开发的一些工具包中接收数据,我想在滚动窗口中显示文本.就目前而言,我正在使用wx.TextCtrl进行文本显示,但是在滚动行为方面存在一些问题.

I have a little logging app (written in wxPython) that receives data from a bit of kit we're developing, and I want to display the text in a scrolling window. As it stands I'm using a wx.TextCtrl for the text display, but I'm having some issues with the scrolling behaviour.

基本上,我想这样做,以便如果滚动条位于窗口的底部(即传入数据的末尾),则添加更多数据应使视图向前滚动.但是,如果视图已经向上滚动一点(例如,用户正在查看诸如错误消息之类的有趣内容),则该应用程序应仅在最后添加文本,而无需进一步滚动.

Basically, I'd like it so that if the scrollbar is at the bottom of the window (i.e. the end of the incoming data), adding more data should scroll the view onwards. If, however the view has been scrolled up a little (i.e. the user is looking at something interesting like an error message), the app should just add the text on the end without scrolling any more.

此刻我有两个问题:

  1. 我不知道如何获取当前滚动位置(对GetScrollPos()的调用似乎不起作用-它们仅返回0).
  2. 我不知道如何获取滚动条的当前范围(对GetScrollRange()的调用仅返回1).

我已经用Google搜索了一下,似乎有一些提示表明GetScrollPos和GetScrollRange对wx.TextCtrl不起作用?其他人在这方面有经验吗?有没有解决这个问题的简便方法,还是我必须自己滚动wx.TextCtrl?

I've googled a bit and there seem to be a few hints that suggest GetScrollPos and GetScrollRange won't work for a wx.TextCtrl? Has anyone else had any experience in this area? Is there a nice easy way to solve the problem or am I going to have to roll my own wx.TextCtrl?

推荐答案

我刚刚测试了一个简单的示例(在EVT_TEXT事件处理程序中检查GetScrollPos(0)GetScrollRange(0)是否为wx.TextCtrl),它对我来说很好用-它们分别返回当前显示的行的索引和行的总数.

I just tested a simple example (checking GetScrollPos(0) and GetScrollRange(0) in EVT_TEXT event handler for wx.TextCtrl) and it works fine for me - they return index of currently shown line and total number of lines, respectively.

也许是您的wxPython版本?我用过:

Maybe the problem is your wxPython version? I used:

>>> import wx
>>> wx.version()
'2.8.9.1 (msw-unicode)'

这篇关于如何从wxPython中的wx.TextCtrl控件获取滚动位置/范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆