I have created a gui that only displays a quote. How can I change the color of all of the word 'thou' in the quote below into blue?. I have tried SetForegroundColour but it changes the entire text into blue.
Here is the code:
import wx
string='''"Have more than thou showest,
Speak less than thou knowest,
Lend less than thou owest,
Ride more than thou goest,
Learn more than thou trowest,
Set less than thou throwest."
—The Fool in King Lear'''
class Quote(wx.Frame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
panel=wx.Panel(self)
self.text=wx.TextCtrl(panel, pos=(20,20), size=(250,220),
style=wx.TE_MULTILINE|wx.TE_READONLY)
self.text.AppendText(string)
self.text.SetForegroundColour("blue")
self.SetSize(300,300)
self.Centre()
self.Show(True)
def main():
app=wx.App()
Quote(None)
app.MainLoop()
if __name__ == '__main__':
main()
You probably need to read up on
RichTextCtrl
https://wxpython.org/Phoenix/docs/html/richtextctrl_overview.htmlJust using
TextCtrl
you can1 set style attributes after the fact (Thanks Robin for your comment) or
2 apply style attributes to the text as you go.
Setting style attributes after the fact using
re
to find all occurrences of your word beforehand:The long winded way of doing this, applying style attributes as you go: