【发布时间】:2012-05-10 13:36:34
【问题描述】:
如何在 StyledTextCtrl 中设置文本颜色,但只能设置一些单词?我的意思是假设我有
露西是蓝色的
我希望只将“蓝色”这个词染成蓝色
【问题讨论】:
标签: python wxpython wxwidgets textcolor wxstyledtextctrl
如何在 StyledTextCtrl 中设置文本颜色,但只能设置一些单词?我的意思是假设我有
露西是蓝色的
我希望只将“蓝色”这个词染成蓝色
【问题讨论】:
标签: python wxpython wxwidgets textcolor wxstyledtextctrl
有关 StyledTextCtrl,请参阅 wxPython 演示。它显示了如何做这件事。我认为您正在寻找的位是这样的:
ed.StartStyling(190, 0xff)
ed.SetStyling(20, 2)
其中 190 是第 190 个字符,您可以为接下来的 20 个字符设置样式。
【讨论】:
要改变一行的样式,你必须得到第一个字节和结束字节的位置。然后,您可以定义从第一个字节开始的样式 (StyleSetSpec) (StartStyling) 并应用于整行 (SetStyling)。您必须在结束字节处重新应用默认样式 (0)。这是我的代码:
# Move to line
self.editname.GotoLine(line-1)
# Get position
pos = self.editname.GetCurrentPos()
# Define style 4
self.editname.StyleSetSpec(4, "back:#ff0000")
# Starts style at position pos
self.editname.StartStyling(pos, 0xffff)
# Until posend position, apply style 4
self.editname.SetStyling(posend-pos, 4)
# Restore style 0 after the ending byte of the line
self.editname.SetStyling(posend, 0)
【讨论】:
在 text_area 是 StyledCtrlText 时使用它
self.text_area.StyleSetSpec(stc.STC_P_DEFAULT,"fore:#FF0000")
接下来放上你要改变颜色的文字
【讨论】: