更改 StyledTextCtrl 的字体颜色 [英] Changing font colour of StyledTextCtrl

查看:43
本文介绍了更改 StyledTextCtrl 的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改以下 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.

当我添加

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

它改变了行号的颜色.(在 StyledTextCtrl 的一侧,它显示了您所在的行).

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?

推荐答案

self.StyleSetForeground(wx.stc.STC_STYLE_DEFAULT,wx.Colour(230, 230, 250)) 只会改变颜色默认样式.

您的代码使用了许多不同的样式,每种样式都指定了自己的颜色.请注意以下代码中的fore"参数:

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)

您的行号似乎使用默认样式,而所有其他文本都使用自己的样式.我不明白在哪里设置样式,所以我无法解释为什么行号不使用 wx.stc.STC_STYLE_LINENUMBER.

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.

因此,要么删除 self.StlyeSetSpec() 调用,要么在初始化程序的末尾包含您的 self.StyleSetForeground() 调用(并且不要忘记调用 self.StyleClearAll() 将所有文本重置为默认样式.

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

这篇关于更改 StyledTextCtrl 的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆