Search code examples
pythonwxpythonwxwidgets

Changing font colour of StyledTextCtrl


I am trying to change the default font colour of the following StyledTextCtrl, I've been testing this for awhile and changing the hex code values however I can't seem to get it to change colour. (I want it to be purple). The current default colour is Black.

When I add

self.StyleSetForeground(wx.stc.STC_STYLE_DEFAULT,wx.Colour(230, 230, 250))

It changes the colour of the line number. (On the side of the StyledTextCtrl, it shows the line you are on).

Does anyone know a solution, or maybe whats causing the confliction?


Solution

  • self.StyleSetForeground(wx.stc.STC_STYLE_DEFAULT,wx.Colour(230, 230, 250)) will only change the colour of the default style.

    Your code uses many different styles, each with their own colour specified. Notice the "fore" argument in the following code:

    self.StyleSetSpec(stc.STC_P_COMMENTLINE,
        "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
    

    It seems like your line numbers are using the default style and all the other text is using their own style. I don't understand where the styles are being set so I can't explain is why the line numbers don't use wx.stc.STC_STYLE_LINENUMBER.

    So, either remove the self.StlyeSetSpec() calls or include your self.StyleSetForeground() call at the end of the initializer (and don't forget to call self.StyleClearAll() to reset all the text to the default style).