0

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

2
Contributors
5
Replies
9
Views
8 Years
Discussion Span
Last Post by juzzy
0

thanks ene for the reply

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

0

To my knowledge you cannot selectively color text with the simple wx.TextCtrl widget, for that you need the wx.StyledTextCtrl widget.

0

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()
Attachments DangerSign.jpg 16.65 KB
0

thats brilliant ene thank you, I think that could be exactly what i'm looking for

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.