Changing font colour of StyledTextCtrl

旧城冷巷雨未停 提交于 2019-12-25 17:39:35

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/10873036/changing-font-colour-of-styledtextctrl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!