is it possible, well yes of course its possible, but does anyone know the best way to alter the colour of a word within a sentence in a wxpython window. I know how to change the colour of the entire text but not a specific word. So for instance if the word "danger" appears within the text it is always red? Any help greatly appreciated
HTML code is easy to learn and you can format text using a simplified version of it, and show it in the wx.html.HtmlWindow() widget. Here is an example: http://www.daniweb.com/forums/post803532-107.html
its not quite what im trying to do but handy to know nonetheless. Im wondering really how you would do it in a textctrl window using straight python (or if there is a wxpython method)?
Oui, before I forget, take a look at the wx.RichTextCtrl example by Snee in the 'Starting wxPython' thread, that seems to be simpler for your purposes: http://www.daniweb.com/forums/post763339-103.html
Here is a simple example:
# a simple sign using wx.richtext.RichTextCtrl()
import wx
import wx.richtext as rt
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
self.SetBackgroundColour("white")
rich = rt.RichTextCtrl(self, wx.ID_ANY, value="")
# default is black text
rich.BeginFontSize(26)
rich.BeginBold()
rich.WriteText(" You are in ")
rich.BeginTextColour('red')
rich.WriteText("danger ")
rich.EndTextColour()
rich.WriteText("at that spot!")
rich.EndBold()
rich.EndFontSize()
rich.WriteText("\n\n The management")
app = wx.App()
mytitle = 'A wx.RichTextCtrl Sign'
width = 600
height = 140
# create the MyFrame instance and show the frame
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()