Start New Discussion within our Software Development Community

Hi, I've tried searching around for other problems similar to mine, and I was unable to find any. I seem to not be able to "color" text in a TextCtrl widget on Windows, but I can on Linux. I have a little screenshot and some code to show this:

Screenshot

Code:

#!/usr/bin/python

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title, size_):
        wx.Frame.__init__(self, parent, title=title, size=size_)
        self.textArea = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.textArea.AppendText("This text should be colored.")
        self.textArea.SetFocus()
        self.Show()
        self.colorText()
        
    def colorText(self):
        self.textArea.SetStyle(5, 9, wx.TextAttr("#ff9c00", "#000000"))

app = wx.PySimpleApp()
frame = MainWindow(None, "Example", (400,300))
app.MainLoop()

Is the SetStyle method not supported on Windows or what? Is there any way I could get around this problem? I think a while ago I read about being able to do this when you initiate the TextCtrl instance (line 8 of my code), by setting "style" equal to some special styling format, but I'm not positive about that.

Thanks in advance.

Sorry for resurrecting the old thread, but I thought I would post the solution to my problem. On line 8 of my code, I create a multiline TextCtrl widget to put my text in. On Linux, this is all that is needed in order to style text. However, in Windows, you must add the wx.TE_RICH2 attribute to a TextCtrl widget in order to do this.

This question has already been answered. Start a new discussion instead.