DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • OpenCV Integration With Live 360 Video for Robotics
  • Introduction to Building Desktop Applications With Electron
  • No Code Expectations vs Reality
  • 5 Simple Tips to Keep Dockerized Apps Secure

Trending

  • Create Your Own AI-Powered Virtual Tutor: An Easy Tutorial
  • Rethinking Recruitment: A Journey Through Hiring Practices
  • Java Virtual Threads and Scaling
  • Debugging Core Dump Files on Linux - A Detailed Guide
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Getting Started with pywebview

Getting Started with pywebview

Need to display some web content in your Python application? We take a look at the pywebview project to help you accomplish exactly that.

By 
Mike Driscoll user avatar
Mike Driscoll
·
Apr. 26, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
12.4K Views

Join the DZone community and get the full member experience.

Join For Free

i stumbled across the pywebview project a couple of weeks ago. the pywebview package “is a lightweight cross-platform wrapper around a webview component that allows the display of html content in its own native gui window.” it uses webkit on osx and linux and trident (mshtml) on windows, which is actually what wxpython’s webview widget also does. the idea behind pywebview is that it provides you with the ability to load a website in a desktop application, kind of like electron .

while pywebview claims it “has no dependencies on an external gui framework,” on windows it requires pythonnet, pywin32 and comtypes to be installed. osx requires “pyobjc,” although that is included with the default python installed in osx. for linux, it’s a bit more complicated. on gtk3 based systems you will need pygobject whereas, on debian based systems, you’ll need to install pygobject + gir1.2-webkit-3.0. finally, you can also use pyqt 4 or 5.

you can use python micro-web frameworks, such as flask or bottle, with pywebview to create cool applications using html5 instead of python.

to install pywebview itself, just use pip:

pip install pywebview

once this is installed and assuming you also have the prerequisites, you can do something like this:

import webview

webview.create_window('my web app', 'http://www.mousevspython.com')

this will load the specified url in a window with the specified title (i.e. the first argument). your new application should end up looking something like this:

image title


the api for pywebview is quite short and sweet and can be found here:

  • https://github.com/r0x0r/pywebview#api

there are only a handful of methods that you can use, which makes them easy to remember. but since you can’t create any other controls for your pywebview application, you will need to do all your user interface logic in your web application.

the pywebview package supports being frozen using pyinstaller for windows and py2app for osx. it also works with virtualenv, although there are known issues that you will want to read about before using virtualenv.

wrapping up

the pywebview package is actually pretty neat and i personally think it’s worth a look. if you want something that’s a bit more integrated to your desktop, then you might want to give wxpython or pyqt a try. but if all you need to do is distribute an html5-based web app, then this package might be just the one for you.

application Cross platform Python (language) Desktop (word processor) Linux (operating system) IT app Bottle (web framework)

Published at DZone with permission of Mike Driscoll, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • OpenCV Integration With Live 360 Video for Robotics
  • Introduction to Building Desktop Applications With Electron
  • No Code Expectations vs Reality
  • 5 Simple Tips to Keep Dockerized Apps Secure

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!