Repainting a wx.TextCtrl

Jesse Aldridge jessealdridge at gmail.com
Fri Feb 1 14:17:20 PST 2008


In the following code, I have a class called Custom_Text_Ctrl which
extends wx.TextCtrl.
I want to do custom painting every time the mouse enters or exits the
text control.
The Refresh method is supposed to trigger a repaint, right?
So why does the paint method never seem to get called?


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"
    self.Refresh()

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

app = wx.App()
frame = wx.Frame( None, title="Test" )
frame.Show()
Custom_Text_Ctrl( frame )
app.MainLoop()




More information about the wxpython-users mailing list