# 5.0 has landed
I am happy to announce the release of pywebview 5. The new version introduces three major features: Android support, DOM manipulation and application settings. For a full changelog, see here.
If you are not familiar with pywebview, it is a Python library that lets you to build GUI for your Python program using HTML, CSS and Javascript. Available for Windows, macOS, Linux and Android. pywebview can be installed with
pip install pywebview
# Android
You can now run your pywebview on Android devices. Mobile experience brings its own limitations though. There is no window manipulation, multi-window or file dialog support. Otherwise, it works same as on other platforms. Head over to Freezing for details how to package your app for Android.
# DOM
With DOM support you can perform jQuery like DOM manipulation, traversal and event handling straight from Python. You can access and modify element's attributes, style and classes as well. A new Element
object represents a DOM node in Python. It is returned by window.dom.get_element
, window.dom.get_elements
and window.dom.create_element
. Body, document and window are conviently exposed as window.dom.body
, window.dom.document
and window.dom.body
respectively. The new Javascript serializer allows you to serialize more Javascript object types and handles circular dependencies, so
Here is a toy example of the new API.
window.dom.document.events.scroll += lambda e: print(window.dom.window.node['scrollY'])
button = window.dom.create_element('<button disabled class="hidden">Button</button>', window.dom.body)
button.style['width'] = '200px'
button.attributes = { 'disabled': False }
button.events.click += click_handler
button.classes.toggle('hidden')
See events, manipulation, events for complete examples.
A much requested feature is a full file path support for drag and drop operations. pywebview enhances DropEvent
by introducing event['dataTransfer']['files'][0]['pywebviewFullPath']
that has full absolute path of a dropped file(s). The full path is available only on Python's side.
# Application settings
pywebview is rather opinionated on how default experience should be. Over the years, I have received numerous feature requests asking to change the default behaviour, which is now possible with application settings. The new version introduces webview.settings
dictionary with following options.
webview.settings = {
'ALLOW_DOWNLOADS': False, # Allow file downloads
'ALLOW_FILE_URLS': True, # Allow access to file:// urls
'OPEN_EXTERNAL_LINKS_IN_BROWSER': True, # Open target=_blank links in an external browser
'OPEN_DEVTOOLS_IN_DEBUG': True, # Automatically open devtools when `start(debug=True)`.
}
Application settings must be set before invoking webview.start()
to have an effect.
# Learn more
Interested in learning more? Head over to usage guide, API reference and examples
# Support the project
pywebview is largely an one-man project, which gets updated sporadically whenever time permits. Any help is appreciated and the best way to contribute is submitting a pull request. Bug fixes are always welcomed. If you wish to submit a new feature, please create an issue and discuss it beforehand. Check out the contributing guide to get started.
If you find pywebview useful and would like to see it developed in the future, considering sponsoring it. If you represent a company, consider becoming a sponsor to get exposure for your company and connect with Python developers.