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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
  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.

Mike Driscoll user avatar by
Mike Driscoll
·
Apr. 26, 17 · Tutorial
Like (3)
Save
Tweet
Share
10.93K 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.

Popular on DZone

  • Cloud Performance Engineering
  • gRPC on the Client Side
  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • Multi-Cloud Integration

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: