WebView2-for-Python is a pure Python binding to Microsoft Edge WebView2, a webview control for Windows 11 based on recent versions of Chrome/Chromium.
It can either be used in standalone mode or embedded into common GUI toolkits, simple wrappers are provided for the following toolkits:
- PyQt5
- PyQt6
- PySide6
- Tkinter
- WinApp (my own Windows API toolkit with dark mode support)
- WinForms (Windows Forms)
- wxPython (wxWidgets)
Minimal code, standalone mode:
from webview2.standalone import *
webview = WebView2(url='https://www.google.com/')
webview.set_focus()
webview.run()For the API check out __init__.py and the various demos.
The standard way to initialize WebView2 is to use the WebView2Loader.dll that comes with Microsofts's WebView2 SDK. WebView2-for-Python instead uses a custom loader.dll. The reason for this is that this small loader.dll allows to use CreateCoreWebView2EnvironmentWithOptions() and pass an instance of CoreWebView2EnvironmentOptions to it, which requires WRL and therefor is hardly possible to implement in plain C or Python/ctypes/libffi code. In particular the loader.dll activates support of browser extensions in the used environment.
A first showcase project is LottieView, a simple and small desktop viewer/player for Lottie animation files.
Another showcase project is SimpleBrowser, still work in progress.
