Table of contents:
Instructions to install the cefpython3 package, clone the repository and run the hello_world.py example:
pip --no-cache-dir install cefpython3==49.0
git clone https://github.com/cztomczak/cefpython.git
cd cefpython/examples/
python hello_world.py
Please note that if you were previously installing cefpython3 package it
is required to use the --no-cache-dir
flag, otherwise pip will end up
with error message No matching distribution found for cefpython3==49.0
.
This happens because 49.0 release occured after 57.0 and 66.0 releases.
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.
See small code snippets that show various CEF features in the examples/snippets/ directory:
- javascript_bindings.py - Communicate between Python and Javascript asynchronously using inter-process messaging with the use of Javascript Bindings.
- javascript_errors.py - Two ways for intercepting Javascript errors.
- network_cookies.py - Implement interfaces to block or allow cookies over network requests.
- onbeforeclose.py - Implement interface to execute custom code before browser window closes.
- ondomready.py - Execute custom Python code on a web page as soon as DOM is ready.
- onpagecomplete.py - Execute custom Python code on a web page when page loading is complete.
- window_size.py - Set initial window size without use of any third party GUI framework.
Examples of embedding using various GUI frameworks:
- gtk2.py: example for PyGTK library (GTK 2)
- gtk3.py: example for PyGObject/PyGI library (GTK 3). Currently broken on Linux/Mac, see top comments in sources.
- qt.py: example for PyQt4, PyQt5 and PySide libraries
- tkinter_.py: example for Tkinter. Currently broken on Mac.
- wxpython.py: example for wxPython toolkit
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, 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.
- Old PyWin32 example: see pywin32.py in the cefpython31 branch
There are ongoing efforts to add these examples to the official examples/ directory, see issues in the tracker.