Try binding the wx.EVT_KEY_UP
event with the wx.TextCtrl
object like this:
(尝试将wx.EVT_KEY_UP
事件与wx.TextCtrl
对象绑定,如下所示:)
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Show Caret Position", size=(400, 140))
panel = wx.Panel(self, wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
text = wx.StaticText(panel, -1, "Text:", (10, 22))
self.textCtrl = wx.TextCtrl(
panel,
-1, "",
(50,5),
size=(250, 50),
style=wx.TE_MULTILINE
)
self.textCtrl.SetInsertionPoint(0)
self.textCtrl.Bind(wx.EVT_KEY_UP,self.onTextKeyEvent)
self.textCtrl.Bind(wx.EVT_LEFT_UP,self.onTextKeyEvent)
self.statusbar = self.CreateStatusBar(1)
panel.SetSizerAndFit(sizer, wx.VERTICAL)
def onTextKeyEvent(self, event):
statusText = "Caret Position: "+str(self.textCtrl.GetInsertionPoint())
self.SetStatusText(statusText,0)
event.Skip()
#Run application
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm()
frame.Show()
app.MainLoop()
I've tested on Windows 7
environment with Python 2.7
+ wxPython 2.8
.
(我已经在Windows 7
环境下使用Python 2.7
+ wxPython 2.8
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…