Start New Discussion within our Software Development Community

hi, just a simple question on a wx.TextCtrl element.
i have this text field where on an application, where the user can add a string on it.
i want a text field with a red text on it.
so i've generated this code:

self.hRepositoryTextfield = wx.TextCtrl(self.hPanel)
self.hRepositoryTextfield.SetDefaultStyle(wx.TextAttr(wx.RED))

if the user copy on this text field some string with applied font on it (for example a black coloured string, or a string with a particular font) the red color, but even any other default styles are not respected.
i would like the style i decide for my wx.TextCtrl is always forced according my settings.
how can i do?

thank you in advance

axel

Another option you can use:

''' wx_FancyText2.py
wxPython's wx.lib.fancytext can apply XML code to color text
'''

import  wx
import  wx.lib.fancytext as fancytext

class FancyText(wx.Panel):
    def __init__(self, parent, text_black, text_red):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

        self.xml_str = '%s<font color="red">%s</font>' % (text_black, text_red)

    def OnPaint(self, evt):
        """generate the fancytext on a paint dc canvas"""
        dc = wx.PaintDC(self)
        fancytext.RenderToDC(self.xml_str, dc, 0, 5)


text_black = '''\
just some normal text
to display ahead of the
special red text
'''

text_red = 'now the red text'

app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY, title='wxPython fancy text',
    pos=(100, 50), size=(500, 250))
FancyText(frame, text_black, text_red)
frame.Show(True)
app.MainLoop()
This article has been dead for over six months. Start a new discussion instead.