Reputation: 8778
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, 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.
Upvotes: 2
Views: 1510
Reputation: 8778
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.
Upvotes: 1
Reputation: 4578
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)
Upvotes: 0