Issue with wx.dc.DrawText()

I have some code for drawing labels with transparent background:

def OnPaint(self, event):
    dc = wx.PaintDC(self)
    dc.SetBackgroundMode(wx.TRANSPARENT)
    font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
    dc.SetFont(font)
    dc.SetPen(self.pen)
    self.text2+='1'
    print self.text2
    dc.DrawText(self.text2, 0, 50)
    dc.DrawText('test', 0, 100)
    event.Skip()

I have a problem with first DrawText call. It never shows updated
string, just whatever it was on the start. Second one with static
string works as expected.

What I want to do is draw some text with color background behind some
characters but not the others.
Any suggestions much appreciated.

Have you verified that there is more than one paint event?

Please make a runnable, small as possible, sample application that demonstrates the problem, and let us know the platform and wx version. MakingSampleApps - wxPyWiki

···

On 3/23/12 12:22 PM, piotr jastrzebski wrote:

I have some code for drawing labels with transparent background:

def OnPaint(self, event):
     dc = wx.PaintDC(self)
     dc.SetBackgroundMode(wx.TRANSPARENT)
     font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
     dc.SetFont(font)
     dc.SetPen(self.pen)
     self.text2+='1'
     print self.text2
     dc.DrawText(self.text2, 0, 50)
     dc.DrawText('test', 0, 100)
     event.Skip()

I have a problem with first DrawText call. It never shows updated
string, just whatever it was on the start. Second one with static
string works as expected.

What I want to do is draw some text with color background behind some
characters but not the others.
Any suggestions much appreciated.

--
Robin Dunn
Software Craftsman