hey
I'm fairly new to wxPython
I'm trying to color my text when using the wxTextCtrl widget
but it won't work I've looked at the demo files source on how to do it but it's to complicated for me I don't get it
can someone show me or know where to find a fairly easy example on how to do this ?
with regareds
Jonas
See if this example helps:
···
--- Jonas Geiregat <kemu@sdf-eu.org> wrote:
I'm fairly new to wxPython
I'm trying to color my text when using the wxTextCtrl widget
but it won't work I've looked at the demo files source on how to
do it but it's to complicated for me I don't get it
can someone show me or know where to find a fairly easy example
on how to do this ?
=================================================================
#!/usr/bin/env python
from wxPython.wx import *
class MyFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, 'Text Colors',
size=(200, 100))
text = 'If supported by the native control, this is red,'
text = text + ' and this is a different font.'
tc1 = wxTextCtrl(self, 40, text,
style=wxTE_MULTILINE|wxTE_RICH2)
tc1.SetInsertionPoint(0)
tc1.SetStyle(44, 47, wxTextAttr("RED", "YELLOW"))
points = tc1.GetFont().GetPointSize()
f = wxFont(points+3, wxROMAN, wxITALIC, wxBOLD, true)
tc1.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f))
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame()
frame.Show(true)
return true
app = MyApp(0)
app.MainLoop()
Notice that you have to use [style=wxTE_RICH2] if you are using
Windows. Then you use wxTextAttr(...) to create the style you want
for the text and .SetStyle(point1, point2, textattr) to change the
color and font. You can also use .SetDefaultStyle and .AppendText
to write text with the color you want.
=====
Donnal Walter
Arkansas Children's Hospital
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.