Reputation: 45
I am trying to get a searchctrl in wxPython. However I am not getting exactly what I want.
I get this:
But I would like to get the SearchCtrl like:
I know that there isn't a big difference, it is just for visual reasons. I declare my SearchCtrl as:
self.searchControl = wx.SearchCtrl(panel, -1, style=wx.TE_PROCESS_ENTER)
Does anybody know how can I declare it in order to get the SearchCtrl as I want?
Upvotes: 0
Views: 632
Reputation: 168776
There are three differences that I can see between what you have and what you want:
None of these three differences are affected by the declaration.
To get the cancel button to show up, call:
self.searchControl.ShowCancelButton(True)
To get the menu indicator to show up, call:
self.SetMenu(menu)
To get the text to appear in the right place, prevent the sizer from vertically resizing your control.
For example:
#!/usr/bin/env python
import wx
app = wx.App(False)
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
sizer = wx.BoxSizer(wx.HORIZONTAL)
menu = wx.Menu()
menu.Append(wx.ID_ABOUT, 'About')
search = wx.SearchCtrl(frame)
search.ShowCancelButton(True)
search.SetMenu(menu)
sizer.Add(search, 0)
frame.SetSizer(sizer)
frame.SetAutoLayout(1)
sizer.Fit(frame)
frame.Show()
app.MainLoop()
yields this:
Upvotes: 3