wxpython textctrl如何找出文本指针的位置

时间:2011-08-17 14:24:37

标签: wxpython textctrl

我需要知道文本指针(闪烁线)在textctrl中的位置。我还想知道是否有可能获得指针所在的整行,或者我是否只需要编写代码以从指针位置获取当前行。

2 个答案:

答案 0 :(得分:2)

您可以使用GetInsertionPoint()查找光标的当前位置。您可以使用:len( self.LogWindow.GetRange( 0, self.LogWindow.GetInsertionPoint() ).split("\n") )来获取行号。

然后你可以使用: GetLineText()获取整行文字......

所以:

curPos = self.LogWindow.GetInsertionPoint
lineNum = self.LogWindow.GetRange( 0, self.LogWindow.GetInsertionPoint() ).split("\n")
lineText = self.LogWindow.GetLineText(lineNum)

应该有用的理论......?

Check This Out...

答案 1 :(得分:1)

您可以使用PositionToXY()查找给定插入点的行号,而不是搜索或计算\n s。

lineNum = self.LogWindow.PositionToXY(curPos)[1]   # lineNum is the y coord from PosToXY()