wxpython textctrl 绑定时不写入
我一直在开发一个简单的 textctrl 项目,以更加熟悉 wxpython,但我遇到了一个小障碍。我正在制作一个简单的代码编辑器,目前正在研究语法突出显示。一切正常,除了因为我将 textctrl 绑定到一个事件:
self.status_area.Bind(wx.EVT_CHAR, self.onKeyPress)
并且我在该定义中有代码:
def onKeyPress (self, event):
Line = self.status_area.GetValue()
它将不再允许用户输入任何字母。我可以毫无问题地删除和创建新行,但如果我输入“hello”,则不会显示任何内容。在调试我的代码时,我知道它通过 onKeyPress() 和里面的代码运行,如果我将代码更改为:
def onKeyPress (self, event):
event.Skip()
它将正常工作。我尝试将正常文本编辑器的工作方式重新编码到 onKeyPress() 中,但它开始变得过于庞大。任何有关此事的帮助将不胜感激。
I have been working on a simple textctrl project to get more acquainted with wxpython and I have hit a small road block. I am making a simple code editor, and I am currently working on the syntax highlighting. Everything works fine except because I have my textctrl bound to an event:
self.status_area.Bind(wx.EVT_CHAR, self.onKeyPress)
and I have code in that definition:
def onKeyPress (self, event):
Line = self.status_area.GetValue()
It will no longer allow the user to type in any letters. I am able to delete and create a new line without any problem, but if I type "hello" nothing will show up. When debugging my code I know its running through onKeyPress() and the code inside and if I change the code to:
def onKeyPress (self, event):
event.Skip()
it will work fine. I tried to recode the normal text editor workings into the onKeyPress() but it began to get too bulky. Any help on the matter would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
EVT_TEXT
而不是EVT_CHAR
。在我的解决方案中,我在event.Skip()
之后添加了它Try
EVT_TEXT
rather thanEVT_CHAR
. In my solution, I added it AFTERevent.Skip()
创建 textctrl
现在绑定
定义:
to creat textctrl
to bind
now the definition: