sending colored text to a TextCtrl in wxpython
Question: I'm trying to send colored text to a TextCtrl widget, but don't know how

    
    
    style = wx.TE_MULTILINE|wx.BORDER_SUNKEN|wx.TE_READONLY|wx.TE_RICH2
    self.status_area = wx.TextCtrl(self.panel, -1,
                                   pos=(10, 270),style=style,
                                   size=(380,150))
    

basically that snippet defines a status box in my window, and I want to write
colored log messages to it. If I just do `self.status_area.AppendText("blah")`
it will append text like I want, but it will always be black. I can't find the
documentation on how to do this.


Answer: You need to call SetStyle to change the text behavior.

    
    
    import wx
    
    class F(wx.Frame):
        def __init__(self, *args, **kw):
            wx.Frame.__init__(self, None)
            style = wx.TE_MULTILINE|wx.BORDER_SUNKEN|wx.TE_READONLY|wx.TE_RICH2
            self.status_area = wx.TextCtrl(self, -1,
                                           pos=(10, 270),style=style,
                                           size=(380,150))
            self.status_area.AppendText("blahblahhblah")
            fg = wx.Colour(200,80,100)
            at = wx.TextAttr(fg)
            self.status_area.SetStyle(3, 5, at)
    
    app = wx.PySimpleApp()
    f = F()
    f.Show()
    app.MainLoop()
    

