Phoenix Logo

phoenix_title wx.lib.wxcairo

This package provides some glue code that allows the Cairo library to draw directly on wx.DC objects, convert to/from wx.Bitmap objects, etc. using either the PyCairo or the newer cairocffi Cairo wrappers. In Cairo terms, the DC is the drawing surface. The CairoContextFromDC function in this module will return an instance of the Cairo Context class that is ready for drawing, using the native cairo surface type for the current platform.


Be sure to import wx.lib.wxcairo before importing the cairo module.

To use Cairo with wxPython you will need to have a few dependencies installed. On Linux and other unix-like systems you may already have them, or can easily get them with your system’s package manager. Just check if libcairo and either cairocffi or pycairo packages are installed.

On Mac you can get Cairo from MacPorts or similar tools. Make sure that the quartz option is turned on so those Mac-specific APIs will be included in the Cairo library when it is built. You can then use pip install cairocffi to get the Python wrappers.

On Windows a copy of the Cairo and related DLLs are included with wxPython inside the wx package folder. These files were extracted from the GTK runtime installers found at the following URLs. You can replace those DLLs with others if you choose, or you can cause the wx_cairocffi module to use DLLs from some other location by setting the CAIRO environment variable.

module_summary Modules Summary

wx_cairocffi wx.lib.wxcairo implementation functions using cairocffi.
wx_pycairo wx.lib.wxcairo implementation functions using PyCairo.



Create a wx.Bitmap from a Cairo ImageSurface.


Creates and returns a cairo.Context object using the wx.DC as the surface. (Only window, client, paint and memory DC’s are allowed at this time.)


Creates and returns a cairo.FontFace object from the native information in a wx.Font.


Create a Cairo ImageSurface from a wx.Bitmap