作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当 TextCtrl/Styled TextCtrl 内的插入符号位置发生更改时,会调用什么事件?我需要绑定(bind)事件以在状态栏中显示插入符的当前位置。
最佳答案
尝试将 wx.EVT_KEY_UP
事件与 wx.TextCtrl
对象绑定(bind),如下所示:
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()
我已使用 Python 2.7
+ wxPython 2.8
在 Windows 7
环境中进行了测试。
关于python - wxPython 插入符移动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364900/
我是一名优秀的程序员,十分优秀!