.. include:: headings.inc .. _PaintEvent: ========================================================================================================================================== |phoenix_title| **PaintEvent** ========================================================================================================================================== A paint event is sent when a window's contents needs to be repainted. The handler of this event must create a :ref:`PaintDC` object and use it for painting the window contents. For example: :: def OnPaint(self, event): dc = wx.PaintDC(self) DrawMyDocument(dc) Notice that you must `not` create other kinds of :ref:`DC` (e.g. :ref:`ClientDC` or :ref:`WindowDC`) in ``EVT_PAINT`` handlers and also don't create :ref:`PaintDC` outside of this event handlers. You can optimize painting by retrieving the rectangles that have been damaged and only repainting these. The rectangles are in terms of the client area, and are unscrolled, so you will need to do some calculations using the current view position to obtain logical, scrolled units. Here is an example of using the :ref:`RegionIterator` class: :: # Called when window needs to be repainted. def OnPaint(self, event): dc = wx.PaintDC(self) # Find out where the window is scrolled to vbX, vbY = self.GetViewStart() # get the update rect list upd = wx.RegionIterator(self.GetUpdateRegion()) while upd.HaveRects(): rect = upd.GetRect() # Repaint this rectangle PaintRectangle(rect, dc) upd.Next() .. _PaintEvent-events: |events| Events Emitted by this Class ===================================== Handlers bound for the following event types will receive a :ref:`PaintEvent` parameter. - EVT_PAINT: Process a ``wxEVT_PAINT`` event. .. note:: Please notice that in general it is impossible to change the drawing of a standard control (such as :ref:`Button`) and so you shouldn't attempt to handle paint events for them as even if it might work on some platforms, this is inherently not portable and won't work everywhere. .. seealso:: :ref:`Events and Event Handling ` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **PaintEvent** .. raw:: html

Inheritance diagram of PaintEvent

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~PaintEvent.__init__` Constructor. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: PaintEvent(Event) A paint event is sent when a window's contents needs to be repainted. **Possible constructors**:: PaintEvent(id=0) .. method:: __init__(self, id=0) Constructor. :param `id`: :type `id`: int