wx.TextCtrl.SetDefaultStyle not working?
7stud
bbxx789_05ss at yahoo.com
Sat Apr 21 08:43:12 EDT 2007
On Apr 20, 8:38 pm, "bcwh... at pobox.com" <bcwh... at pobox.com> wrote:
> I'm running Python2.5 with wxPython v2.8.3.0 under WinXP and I cannot
> get the SetDefaultStyle method to work.
>
> I'm trying:
>
> self.output.SetDefaultStyle(wx.TextAttr(wx.RED))
> self.output.AppendText(text)
> self.output.SetDefaultStyle(wx.TextAttr())
>
> where "self.output" is a TextCtrl window. The text appears, but it's
> always black. If I print the output of
> self.output.GetDefaultStyle().GetTextColour() before resetting it back
> to default, I see "(255, 0, 0, 255)". After reset, it's "(-1, -1, -1,
> 255)".
>
> The font in that window is the system default.
>
> Am I doing something wrong?
>
> -- Brian
You didn't show the code that creates the TextCtrl. Is it something
like this:
self.output = wx.TextCtrl(myFrame, -1, style=wx.TE_MULTILINE |
wx.TE_RICH2)
On my platform, styling the text doesn't work for single line
TextCtrl's(which seems kind of stupid), and on Windows I think you are
required to specify wx.TE_RICH2 to style the text. This following
code colors the entered text red for me:
--------
import wx
myApp = wx.App(False)
myFrame = wx.Frame(None, -1, title="Test")
panel = wx.Panel(myFrame, -1)
my_tc = wx.TextCtrl(myFrame, -1, style=wx.TE_MULTILINE | wx.TE_RICH2)
my_tc.SetDefaultStyle(wx.TextAttr("red") ) #wx.RED works too
myFrame.Show()
myApp.MainLoop()
--------
More information about the Python-list
mailing list