来自用户在字段中选择文本的wxPython事件?

来自用户在字段中选择文本的wxPython事件?,wxpython,Wxpython,如何在wx.TextCtrl、wx.lib.editor、wx.richtext和wx.stc等小部件中捕获用户文本选择的起点和终点?我应该参加什么活动 我只是在学习wxPython,并根据示例编写了以下基本代码 import wx import wx.lib.editor as editor class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, paren

如何在wx.TextCtrl、wx.lib.editor、wx.richtext和wx.stc等小部件中捕获用户文本选择的起点和终点?我应该参加什么活动

我只是在学习wxPython,并根据示例编写了以下基本代码

import wx
import wx.lib.editor as editor

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200,100))
        self.control = editor.Editor(self, -1, style=wx.SUNKEN_BORDER)
        self.Show(True)

app = wx.App(False)
frame = MyFrame(None, 'test editor')
app.MainLoop()
多谢各位
-大卫

有点晚了,但万一还是有帮助的话。您可以使用win32api模块:

import wx
import win32api

class MyTextCtrl(wx.TextCtrl):
    def __init__(self, parent):
        self.hwnd = self.GetHandle()

    def _GetSel(self):
        EM_GETSEL: int = 0xB0
        n = win32api.SendMessage(self.hwnd, EM_GETSEL, 0, 0)
        return win32api.LOWORD(n), win32api.HIWORD(n)

    def IsFullTextSelected(self):
       return self._GetSel() == (0, len(self.Value))

虽然有点晚了,但万一还是有帮助的话。您可以使用win32api模块:

import wx
import win32api

class MyTextCtrl(wx.TextCtrl):
    def __init__(self, parent):
        self.hwnd = self.GetHandle()

    def _GetSel(self):
        EM_GETSEL: int = 0xB0
        n = win32api.SendMessage(self.hwnd, EM_GETSEL, 0, 0)
        return win32api.LOWORD(n), win32api.HIWORD(n)

    def IsFullTextSelected(self):
       return self._GetSel() == (0, len(self.Value))