Table of contents:
Instructions to install the cefpython3 package, clone the repository and run the hello_world.py example:
pip install cefpython3==66.0
git clone https://github.com/cztomczak/cefpython.git
cd cefpython/examples/
python hello_world.py
Examples provided in the examples/ root directory are actively maintained. If there are any issues in examples read top comments in sources to see whether this is a known issue with available workarounds.
- hello_world.py - Basic example, doesn't require any third party GUI framework to run
- tutorial.py - Example from Tutorial
- screenshot.py - Example of off-screen rendering mode to create a screenshot of a web page. The code from this example is discussed in great details in Tutorial in the Off-screen rendering section.
For small code snippets that show various CEF features and are easy to understand see the README-snippets.md document.
Examples of embedding CEF browser using various GUI frameworks:
- gtk2.py: example for PyGTK library (GTK 2)
- gtk3.py: example for PyGObject / PyGI library (GTK 3). Currently broken on Mac (#310).
- pysdl2.py: off-screen rendering example for PySDL2 library. Example has some issues that are reported in Issue #324.
- pywin32.py: example for pywin32 library
- qt.py: example for PyQt4, PyQt5 and PySide libraries. PyQt4 and PySide examples are currently broken on Linux, see Issue #452.
- tkinter_.py: example for Tkinter. Currently broken on Mac (#309).
- wxpython.py: example for wxPython toolkit. This example implements High DPI support on Windows.
- PyInstaller example: example of packaging app using PyInstaller packager. Currently this example supports only Windows platform.
There are also available unit tests and its usage of the API can be of some use. See:
- main_test.py - windowed rendering general tests
- osr_test.py - off-screen rendering tests
There are even more examples available, they do not reside in the examples/ directory. Some of them were created for old verions of CEF and were not yet ported to latest CEF. Some of them are externally maintained.
- Kivy framework: see Kivy wiki page.
- Panda3D game engine: see Panda3D wiki page.
- PyGame/PyOpenGL: see gist by AnishN
- Example of implementing ResourceHandler with the use of WebRequest object and WebRequestClient interface to allow for reading/modifying web requests: see the wxpython-response.py example in the cefpython31 branch.
- Example of using Python network library (urllib3/openssl) instead of Chromium's network library - see gist by Massimiliano Dal Cero
- Example of passing exceptions from Python to Javascript and using await syntax to receive values from python return values - see Managed python calls example by Elliot Woods
Here is a list of issues in the tracker to create or upgrade examples:
- Issue #323 - "Create cocos2d example"
- Issue #322 - "Create pyglet example"
- Issue #312 - "Easy to use CefBrowser widgets for many popular GUI toolkits"
- Issue #301 - "Fix cefpython3.wx package to work with latest v55+"
- Issue #289 - "Pygame / PyOpenGL example"
- Issue #288 - "Create panda3d_.py example"
- Issue #285 - "[kivy_.py] Refactor example, make it work cross-platform and move it to examples/"
- Issue #252 - "Use CEF views in Hello World, Tutorial and Offscreen examples, and in Unit tests"
- Issue #224 - "Port CEF 1 examples to CEF 3"
- Issue #109 - "The ResourceHandler example"
Packaging examples:
- Issue #407 - "Example of packaging app using Cython compiler"
- Issue #396 - "Example of packaging app using Nuitka compiler"
- Issue #338 - "Example of packaging app using cx_Freeze"
- Issue #337 - "Example of packaging app using py2app"
- Issue #135 - "Example of packaging app using pyinstaller"