[wxPython] I'd like to catch mouse click events within a textcontrol

F. GEIGER fgeiger at datec.at
Fri Nov 22 02:48:39 EST 2002


Thanks for the info, Cliff, and for the sample code. Perfect.

Stupid me: After all a textCtrl is a window...

Kind regards
Franz


"Cliff Wells" <LogiplexSoftware at earthlink.net> schrieb im Newsbeitrag
news:mailman.1037919514.18620.python-list at python.org...
On Thu, 2002-11-21 at 10:24, F. GEIGER wrote:
> I'd like to catch mouse click events within a text control and then read
the
> mouse pointer position. Alas, the only events I found in the dox are,
> EVT_TEXT, EVT_TEXT_ENTER, EVT_TEXT_URL, EVT_TEXT_MAXLEN.

Those events are specific to the wxTextCtrl, but you can also use the
events that are common to *all* controls:

from wxPython.wx import *

class ClickableText(wxTextCtrl):
    def __init__(self, parent, id):
        wxTextCtrl.__init__(self, parent, id)
        EVT_LEFT_DOWN(self, self.OnClick)

    def OnClick(self, event):
        print event.GetX(), event.GetY()
        raise SystemExit

app = wxPySimpleApp()

frame = wxDialog(None, -1, "Test")
text = ClickableText(frame, -1)
frame.ShowModal()

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308






More information about the Python-list mailing list