0

I'm using wxpython to create GUI with python, now, is there a way to color specific part of the text?

Example (using Tkinter):

https://i.stack.imgur.com/fGAVA.png

Here is my Print function:

def Print(self, String):
    ''' Print Received Data '''

    self.text_serverLog.AppendText(datetime.now().strftime("[%H:%M:%S] " + String + "\n"))

I found the function SetForegroundColour but sadly its color the whole TextCtrl.

I'm using Win7, python 2.7, wxpython. Thanks.

user2367115
  • 53
  • 3
  • 10
  • make sure you're specifying text.SetForegroundColour see http://stackoverflow.com/questions/1785227/change-the-colour-of-a-statictext-wxpython –  May 17 '13 at 17:28
  • I don't think you can do that with `TextCtrl`, but you should be able to do it with [`RichTextCtrl`](http://wxpython.org/docs/api/wx.richtext.RichTextCtrl-class.html). – Aya May 17 '13 at 17:29
  • If you go to the [wxPython download page](http://www.wxpython.org/download.php#stable), and download/install the `wxPython2.8-win32-docs-demos` installer, there's a bunch of useful demos (with full source code) including an example of what you're trying to do. – Aya May 17 '13 at 17:36
  • Thank you all, I'm using now `RichTextCtrl` object. Here is an example how to color a specific text: http://stackoverflow.com/questions/7734028/different-foreground-colors-for-each-line-in-wxpython-wxtextctrl – user2367115 May 17 '13 at 17:41

1 Answers1

1

You can use the wx.TextCtrl in RichText mode by setting its style flag to wx.TE_RICH or wx.TE_RICH2. You can also use the aforementioned RichTextCtrl or the StyledTextCtrl (1 or 2). There's also FancyText, but I think that's more of a helper for drawing text than a real control the user can edit. Regardless, all of these widgets have examples in the wxPython demo package, which you can find at the wxPython website's download page.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88