Flask with pywebview Example
I mashed up 2 things:
Here’s the project dir structure (minimal Flask):
C:\Users\joeco\PycharmProjects\pyWebviewFlask>tree /F /A
Folder PATH listing for volume Windows
Volume serial number is F2FB-4810
C:.
| pyWebviewFlask.py
|
+---.idea
| encodings.xml
| misc.xml
| modules.xml
| pyWebviewFlask.iml
| workspace.xml
|
+---static
\---templates
Here’s the code in pyWebviewFlask.py:
"""
__author__ = "Joe Dorocak (JoeCodeswell@gmail.com)"
__copyright__ = "Copyright 2016, Joe Dorocak (JoeCodeswell.com)"
__license__ = "MIT"
PyCharm project type: flask
Templating language (std for Flask) : Jinja2
pywebview == webview: https://github.com/r0x0r/pywebview (by Roman Sirokov already installed for py2 & py3)
https://github.com/r0x0r/pywebview/blob/master/examples/http_server.py
Flask views: http://flask.pocoo.org/docs/0.11/tutorial/views/
https://opensource.org/licenses
"""
from flask import Flask
import webview
import sys
import threading
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello to the World!'
def start_server():
app.run()
if __name__ == '__main__':
""" https://github.com/r0x0r/pywebview/blob/master/examples/http_server.py
"""
t = threading.Thread(target=start_server)
t.daemon = True
t.start()
webview.create_window("It works, Joe!", "http://127.0.0.1:5000/")
sys.exit()
Here’s a link to a screenshot of the result:
flask-pyview-shot
#app-development-2, #flask, #python, #pywebview, #webview