wx.SetTextForeground doesn't set DC color properly in wxPython
Question: I have the following code and I'm trying to change the text color of DC. I
have searched the internet and found that SetTextForeground should be used for
this, but somehow I'm unable to make it work.

    
    
    import wx
    
    class GUI():        
        def __init__(self):
            self.InitUI()
    
        def InitUI(self):
            self.window  = wx.Frame(None, wx.ID_ANY, "Example Title")
    
            textList = ['text1', 'text2']
            for i in range(len(textList)):
                bmp = wx.Image('images/step_background.png').Rescale(160, 40).ConvertToBitmap()
                bmp = self.drawTextOverBitmap(bmp, textList[i])
                control = wx.StaticBitmap(self.window, -1, bmp, (0, 30*i+20), size=(160,30))
            self.window.Show()
    
    
        def drawTextOverBitmap(self, bitmap, text='', color=(0, 0, 0)):
                dc = wx.MemoryDC(bitmap)
                dc.SetTextForeground(color)
                w,h = dc.GetSize()
                tw, th = dc.GetTextExtent(text)
                dc.DrawText(text, (w - tw) / 2, (h - th) / 2) #display text in center
                return bitmap
    
    if __name__ == '__main__':
        app = wx.App()
        gui = GUI()
        app.MainLoop()
    

Do you have any ideas what am I doing wrong? I would be grateful for any idea.

Thank you


Answer: You are right, transparency is the issue here. Tried your code on a non-
transparent image and it works fine displaying the color you set.

Quoting from the [official
docs](http://docs.wxwidgets.org/trunk/classwx_d_c.html):

> In general wxDC methods don't support alpha transparency and the alpha
> component of wxColour is simply ignored and you need to use
> wxGraphicsContext for full transparency support.

So try creating a graphics context like:

    
    
            dc = wx.MemoryDC(bmp)
            gc = wx.GraphicsContext.Create(dc)
            font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
            gc.SetFont(font, "Red")
            w,h = dc.GetSize()
            tw, th = dc.GetTextExtent(textList[i])
            gc.DrawText(textList[i], (w - tw) / 2, (h - th) / 2)
    

