SearchCtrl shows text in two colors -- gray for the DescriptiveText
(e.g. "Search") and black for what the user types in. But if you use
the ChangeValue(new_text) method, it updates the text, but keeps the
current color. This means that if no text is showing in the search
field, new_text will show up gray. Even changing the text via the
keyboard doesn't change it back to black. Instead, it remains gray
until you delete all characters, change the focus from the SearchCtrl,
then put the focus back in the SearchCtrl. This is a problem for
users who naturally assume that the gray text means the control is
disabled.
I've tried forcing the text color in both the SearchCtrl and the
underlying TextCtrl, but it doesn't work. I'm running version
2.8.11.0 on Windows 7, if that makes any difference.
Here is code to see the problem.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title='Set SearchCtrl Value')
self.panel = wx.Panel(self)
self.button = wx.Button(self.panel, -1, 'Change search
string')
self.search = wx.SearchCtrl(self.panel)
self.static = wx.StaticText(self.panel, -1, 'Type string
here:')
self.text = wx.TextCtrl(self.panel, -1, 'I was here')
# Layout
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.search)
sizer.Add(self.button)
sizer.Add(self.static)
sizer.Add(self.text)
self.panel.SetSizer(sizer)
sizer2 = wx.BoxSizer()
sizer2.Add(self.panel, 1, wx.EXPAND, 0)
self.SetSizer(sizer2)
# Bind events
self.Bind(wx.EVT_BUTTON, self.OnButton, self.button)
def OnButton(self, event):
self.search.ChangeValue(self.text.Value)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
frame.Center()
frame.Raise()
app.MainLoop()