GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Table of Contents
  • wx.PaintEvent
  • Show Source
  • index
  • modules
  • next
  • previous
  • Home
  • Gallery
  • wx

This view

  • Original page
  • New address

GeezerVison is showing docs.wxpython.org — wx.PaintEvent — wxPython 4.3.2 Docs

phoenix_title wx.PaintEvent¶

A paint event is sent when a window’s contents needs to be repainted.

The handler of this event must create a wx.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 wx.DC (e.g. wx.ClientDC or wx.WindowDC) in EVT_PAINT handlers and also don’t create wx.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 wx.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()

events Events Emitted by this Class¶

Handlers bound for the following event types will receive a wx.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 wx.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.

See also

Events and Event Handling


class_hierarchy Class Hierarchy¶

Inheritance diagram for class PaintEvent:

Inheritance diagram of PaintEvent


method_summary Methods Summary¶

__init__

Constructor for exclusive use of wxWidgets itself.


api Class API¶

class wx.PaintEvent(Event)¶

Possible constructors:

PaintEvent(window) -> None

A paint event is sent when a window’s contents needs to be repainted.


Methods¶

__init__(self, window)¶

Constructor for exclusive use of wxWidgets itself.

Note that the objects of this class can not be created from application code, they’re only created by the library itself. If you need a window to be repainted, use wx.Window.Refresh instead of trying to manually create an event of this class.

Parameters:

window (wx.Window)

Return type:

None

© Copyright 2012-2026, The wxPython Team. Created using Sphinx 9.1.0 and the python-docs-theme.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.