Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:17:23+00:00 2026-06-15T18:17:23+00:00

#! /usr/bin/python #SearchCtrlProblem import wx class ControlPanel(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent,

  • 0
#! /usr/bin/python

#SearchCtrlProblem

import wx

class ControlPanel(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(200,200))
        self.panel = wx.Panel(self, -1)
        vbox = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(vbox)
        self.DoLayout()
        self.Centre()
        self.Show(True)        

    def DoLayout(self):
       vbox = self.panel.GetSizer()

        self.tc = tc = wx.TextCtrl(self.panel, size = (140,-1), style=wx.TE_PROCESS_ENTER)
        vbox.Add(tc, 0, wx.ALL, 15)
        tc.Bind(wx.EVT_TEXT_ENTER, self.OnTextCtrl, id=tc.GetId())

        self.sc = sc = wx.SearchCtrl(self.panel, size = (140,-1), style=wx.TE_PROCESS_ENTER)
        sc.ShowSearchButton(True)
        sc.ShowCancelButton(True)
        vbox.Add(sc, 0, wx.ALL, 15)

        sc.Bind(wx.EVT_TEXT_ENTER, self.OnSearchCtrl, id=sc.GetId())

        self.bn = bn = wx.Button(self.panel, -1, 'Reset', (140,-1))
        vbox. Add(bn, 0, wx.ALL,15)
        bn.Bind(wx.EVT_BUTTON, self.OnReset, id = bn.GetId())

        vbox.Layout()
        self.Refresh()       

    def OnTextCtrl(self, evt):
        value = self.tc.GetValue()
        self.sc.SetValue(value)

    def OnSearchCtrl(self, evt):
        value = self.sc.GetValue()
        self.tc.SetValue(value) 

    def OnReset(self, evt):
        self.panel.DestroyChildren()
        self.DoLayout()

app = wx.App()
ControlPanel(None, -1, '')
app.MainLoop()

I wrote this silly program to demonstrate the question.
+ When I run program, if I start by typing into the search box sc then press enter, everything is OK with black text in sc. Now, I can type in text box tc then press enter, text in sc still black

  • However, if I start by typing in search box sc then press enter, text in sc will turn grey. From that point, if I try to type tc then press enter, the text in sc is always grey.

Note: before start typing, you can reset the layout by pressing on the button “Reset”. The problem happened on Linux RedHat 4.5.1-3, Python 2.7. When I tried this on Mac OS X 10.8, Python 2.7.2, this problem didn’t happen.

How can I make the text in SearchCtrl always black?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:17:24+00:00Added an answer on June 15, 2026 at 6:17 pm

    This is a bug in wxWidgets 2.8.12.

    The control will only set the text color to black when it receives focus while the text matches the hint text (the grey text shown when the control is empty).

    To fix this without upgrading to a never version, you have to focus the control before changing its text:

    wnd = self.FindFocus()   # get currently focused window
    self.sc.SetFocus()       # trigger the color update (if needed)
    self.sc.SetValue(value)
    if wnd: wnd.SetFocus()   # restore previous focus
    else: self.SetFocus()    # set focus to frame if none was set
    

    To remove the text from the wxSearchCtrl and restore the grayed hint text, a simple call to Clear() will do (in 2.8.12 anyway).

    That bug is fixed in the latest development release (2.9.4). However, clearing the text does not restore the hint text.

    On OS X 10.3 and later, the native search control is used which does not exhibit this behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#!/usr/bin/python import wx import os import sys class MyFrame(wx.Frame): def __init__(self, parent, id, title):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter import twitter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent=parent
#!/usr/bin/python # -*- coding: iso-8859-15 -*- import twitter class twitt(): def __init__(self): consumer_key =
okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,
I've been playing around with Python's SocketServer: #!/usr/bin/python import SocketServer class EchoHandler(SocketServer.BaseRequestHandler): def handle(self):
#!!/usr/bin/python # Qt modules from PyQt4 import QtCore, QtGui import sys class gui(QtGui.QDialog): def
here is my code #!/usr/bin/python # -*- coding:utf-8 -*- import sys import pysvn def
#!/usr/bin/python class Bar(object): @staticmethod def ruleOn(rule): if isinstance(rule, tuple): print rule[0] print rule[0].__get__(None, Foo)
This is my model class #!/usr/bin/python from django.db import models class olWS(models.Model): country=models.CharField(max_length=4) comment=models.TextField()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.