Core Windows/Controls → SearchCtrl
overview = """\
The Editor class implements a simple text editor using wxPython. You
can create a custom editor by subclassing Editor. Even though much of
the editor is implemented in Python, it runs surprisingly smoothly on
normal hardware with small files.
"""
import wx
class Frame(wx.Frame):
ID_Hello = wx.NewId()
def __init__(
self, parent=None, id=wx.ID_ANY, title='wx.SearchCtrl', pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.SetIcon(wx.Icon('wxWidgets.ico', wx.BITMAP_TYPE_ICO))
panel = wx.Panel(self, wx.ID_ANY)
self.searchCtrl = wx.SearchCtrl(panel, wx.ID_ANY, pos=(20, 20), size=(200, -1),
style=wx.TE_PROCESS_ENTER)
self.searchCtrl.ShowSearchButton(True)
self.searchCtrl.ShowCancelButton(True)
self.searchCtrl.SetMenu(self.MakeMenu())
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.OnSearch, self.searchCtrl)
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.OnCancel, self.searchCtrl)
self.Bind(wx.EVT_TEXT_ENTER, self.OnDoSearch, self.searchCtrl)
self.Bind(wx.EVT_MENU, self.OnHello, id=self.ID_Hello)
def OnSearch(self, event):
pass
def OnCancel(self, event):
pass
def OnDoSearch(self, event):
wx.MessageBox('You want to search %s?' % self.searchCtrl.GetValue(), 'Prompt')
def MakeMenu(self):
menu = wx.Menu()
menu.Append(self.ID_Hello, 'Hello')
return menu
def OnHello(self, event):
wx.MessageBox('Hello from wx.SearchCtrl', 'Prompt')
def TestFrame():
app = wx.PySimpleApp()
frame = Frame()
frame.Centre()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
TestFrame()