Repainting a wx.TextCtrl

Jesse Aldridge jessealdridge at gmail.com
Fri Feb 1 14:58:12 PST 2008


I tried painting from the text control's parent.
That works, but I want to paint over the child widgets, and the
painting seems to go under.
If I could somehow do custom painting after the children were painted,
that would also solve my problem.


import wx

class Custom_Text_Ctrl( wx.TextCtrl ):
  def __init__( self, parent ):
    wx.TextCtrl.__init__( self, parent )

    self.Bind( wx.EVT_PAINT, self.on_paint )
    self.Bind( wx.EVT_ENTER_WINDOW, self.on_mouse_enter )
    self.Bind( wx.EVT_LEAVE_WINDOW, self.on_mouse_leave )

  def on_paint( self, e ):
    print "painting..."

  def on_mouse_enter( self, e ):
    print "mouse entered"
    frame.Refresh()

  def on_mouse_leave( self, e ):
    print "mouse left"
    frame.Refresh()

class Custom_Frame( wx.Frame ):
  def __init__( self ):
    wx.Frame.__init__( self, None, title="Test" )

    self.Bind( wx.EVT_PAINT, self.on_paint )

  def on_paint( self, e ):
    print "painting frame"
    e.Skip()
    dc = wx.PaintDC( self )
    dc.DrawRectangle( 0,0,100,100 )

app = wx.App()
frame = Custom_Frame()
frame.Show()
Custom_Text_Ctrl( frame )
app.MainLoop()




More information about the wxpython-users mailing list