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.Clear()
dc.DrawBitmap(bitmap, sx, sy, True)

# Draw the text overlay
dc.SetTextForeground(wx.WHITE)
dc.SetTextBackground(wx.BLACK)
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?

2023-01-27_183648

Hi Jim,

dc.SetBackgroundMode(wx.BRUSHSTYLE_SOLID)

should be declared before calling DrawText.

See also: wx.DC — wxPython Phoenix 4.2.0 documentation

Perfect. Thanks.