开发者

wxPython: how to listen to EVT_KEY_DOWN on SearchCtrl?

In my application I want a search box, probably like the one provided by wx.SearchCtrl, with the search button and the cancel button included. I also want to know when the user presses Up or Down, so that I can browse through the search results. When I make a demo with wx.TextCtrl I can bind the event like this

self.textbox = wx.TextCtrl(self)
self.textbox.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown,开发者_JS百科 self.textbox)

But as soon as I change textbox to wx.SearchCtrl I cannot catch the event anymore. Can I make the binding work with wx.SearchCtrl or do I have to implement my textbox so that it looks like one?

If that matters, I'm developing on Ubuntu (Gnome) and the application should work well on both Linux and Windows.


A workaround seems to be using EVT_KEY_UP, i.e

self.textbox.Bind(wx.EVT_KEY_UP, self.OnKeyUp, self.textbox)

However, this way the key press is not repeatable (you have to release the key in order for the event to be fired). I'm still looking for better ways.


Use a different event, as per the docs.

self.textbox = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER)
self.Bind(wx.EVT_TEXT, self.OnKeyDown, self.textbox)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜