Displaying white text on black background

When displaying a picture I want to overlay (at the top left) some picture info. I want white text on a black background so that it is readable no matter what colours are in the picture. The code that paints the display is:

# Draw the image
dc = wx.AutoBufferedPaintDC(self)
dc.DrawBitmap(bitmap, sx, sy, True)

# Draw the text overlay
note = f'{self.files[self.index]}    {self.index+1} of {len(self.files)}'
dc.DrawText(note, 5, 5)

What I actually get is white text on whatever the picture is. What am I doing wrong?


Hi Jim,


should be declared before calling DrawText.

See also: wx.DC — wxPython Phoenix 4.2.0 documentation

Perfect. Thanks.