gpt4 book ai didi

python - wxPython 插入符移动事件

转载 作者:行者123 更新时间:2023-12-01 06:01:14 25 4
gpt4 key购买 nike

当 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.8Windows 7 环境中进行了测试。

Here is how it should look like

关于python - wxPython 插入符移动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com