Pablo
Pablo

Reputation: 45

SearchCtrl in wxPython looks different

I am trying to get a searchctrl in wxPython. However I am not getting exactly what I want.

I get this:

enter image description here

But I would like to get the SearchCtrl like:

enter image description here

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

Answers (1)

Robᵩ
Robᵩ

Reputation: 168776

There are three differences that I can see between what you have and what you want:

  1. The cancel button (X in a circle)
  2. The menu indicator (the arrow next to the magnifying glass).
  3. The location of the word "Search"

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:

enter image description here

Upvotes: 3

Related Questions