wx.DC.DrawText and pen color

2,004 views
Skip to first unread message

Nat Echols

unread,
Dec 20, 2011, 6:47:49 PM12/20/11
to wxpython-users
We've just discovered that changing the pen and drawing text, e.g.

dc.SetPen(wx.Pen((255,0,0)))
dc.DrawText(10,10, "Hello, world!")

doesn't actually result in text in the desired color - instead it uses
whatever the foreground color of the underlying widget is set to. So
I can't draw text in multiple colors on a wx.DC right now. Is there
something I'm missing? (wxPython 2.9.4, wxOSX-Cocoa, OS 10.6, if it
matters.)

thanks,
Nat

Tim Roberts

unread,
Dec 20, 2011, 9:07:43 PM12/20/11
to wxpytho...@googlegroups.com
Nat Echols wrote:
> We've just discovered that changing the pen and drawing text, e.g.
>
> dc.SetPen(wx.Pen((255,0,0)))
> dc.DrawText(10,10, "Hello, world!")
>
> doesn't actually result in text in the desired color - instead it uses
> whatever the foreground color of the underlying widget is set to.

Text is never drawn with the current pen. It's drawn with the current
text color. Try
dc.SetTextForeground((255,255,0))

This is a historical implementation detail in Windows GDI. The pen is
used for lines, the brush is used for fills, and text had its own
attributes.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Nat Echols

unread,
Dec 21, 2011, 3:13:48 PM12/21/11
to wxpytho...@googlegroups.com
On Tue, Dec 20, 2011 at 6:07 PM, Tim Roberts <ti...@probo.com> wrote:
> Text is never drawn with the current pen.  It's drawn with the current
> text color.  Try
>   dc.SetTextForeground((255,255,0))

Thanks, that appears to do what I wanted, at least on Mac.

-Nat

Reply all
Reply to author
Forward
0 new messages