Hi,
I am trying to set the background coulour of a textctrl. Neither of the
following methods works (linux, wxPython 2.6.3.3):
1) SetBackgroundColour, followed by Refresh(True)
2) SetStyle(0,-1,TextAttr(wx.RED,wx.BLACK))
3) subclassing and binding to PAINT/ERASE events, the handlers are never called
Basically I want to have a TextCtrl with optical feedback for the validity of
the input, i.e. if the input is not acceptable, the background colour should
turn to red, while still allowing the user to enter everything (in contrast to
using a Validator). Has someone maybe done that already?
Hi,
I am trying to set the background coulour of a textctrl. Neither of the
following methods works (linux, wxPython 2.6.3.3):
1) SetBackgroundColour, followed by Refresh(True)
2) SetStyle(0,-1,TextAttr(wx.RED,wx.BLACK))
3) subclassing and binding to PAINT/ERASE events, the handlers are never called
Basically I want to have a TextCtrl with optical feedback for the validity of
the input, i.e. if the input is not acceptable, the background colour should
turn to red, while still allowing the user to enter everything (in contrast to
using a Validator). Has someone maybe done that already?
Most likely your gtk theme is blocking the ability to change the background color. Some allow it, some don't. In the past some people have gotten around this limitation by having a border around the control[1] and changing the color of it.
[1] Either by drawing it on the parent, or by putting the control in another panel that is sized a couple pixels larger than the control, and then changing the bg color of that panel when needed.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Well, I am not sure how you would handle the type of thing that you are talking about, in terms of dynamically updating the coloring other than to say that it would of course hinge upon handing all of the user events that come in. However, working with the TextCtrl as much as I have lately, I have found that I had to do a set of calls to initialize my TextCtrl the way I wanted it:
self.SetBackgroundColour(wx.NamedColor(“BLACK”))
self.SetDefaultStyle(wx.TextAttr(self.CDB.Find(self.AnsiForeground),
self.CDB.Find(self.AnsiBackground),
wx.Font(self.AnsiFontSize, self.AnsiFontFamily,
self.AnsiFontStyle, self.AnsiFontWeight,
self.AnsiFontUnderline)))
This is for a custom AnsiTextCtrl which is subclassed from TextCtrl, however, the same two calls should be able to be used. IIRC, SetBackgroundColour() sets the background color of the entire window, and the second parameter to wx.TextAttr (in the SetDefaultStyle call) is what sets the background color of the new text printed in the window. CDB, by the way, is a private color database that I am using within the derived text control, which I am using to support ANSI color.
HTH,
Mike
···
On Sun, 2006-11-05 at 03:21 +0000, Christian Kristukat wrote:
Hi,
I am trying to set the background coulour of a textctrl. Neither of the
following methods works (linux, wxPython 2.6.3.3):
1) SetBackgroundColour, followed by Refresh(True)
2) SetStyle(0,-1,TextAttr(wx.RED,wx.BLACK))
3) subclassing and binding to PAINT/ERASE events, the handlers are never called
Basically I want to have a TextCtrl with optical feedback for the validity of
the input, i.e. if the input is not acceptable, the background colour should
turn to red, while still allowing the user to enter everything (in contrast to
using a Validator). Has someone maybe done that already?