Reputation: 112
I would like to take the functionality of python and pair it with a nice html/css interface. whats the best way to make it run in the background without the need for an external server. ideally you wouldn't even need python installed, just an exe. any suggestions would be very helpful. Thank you
Upvotes: 0
Views: 1427
Reputation: 1
from flask import Flask,render_template
import webview
app = Flask(__name__, static_folder='./assets', template_folder='./templates')
@app.route('/')
def welcome():
mylist = [1,2,3,4,5,6,7]
return render_template("index.html",mylist=mylist,name='mefiz.com')
@app.route('/home')
def welcome2():
return render_template("index.html",name='mefiz.com')
webview.create_window('Flask example', app)
webview.start()
Upvotes: 0
Reputation: 357
if you want to run it just as a local application and want to design the user interface using HTML and CSS, you can use the following method.
first install pywebview using:
pip install pywebview
then create a new python script in the home directory of your html/css project and name it app.py (just as an example)
put the following content in this file:
import webview
import os
default_page = "index.html"
webview.create_window("Title", url=f"file://{os.getcwd()}/{default_page}")
webview.start()
Here just change the default_page variable to the main page of your application and the word "Title"
with your Title.
you will have a running python script now and to convert it into an exe, you can use tools like py2exe or pyinstaller. Also after compiling it into an exe, copy the produced exe (and other dependencies) into the home directory of your html/css project otherwise it will throw a 404 error.
Note: There was a bug found in pyinstaller 3.5 which couldn't compile pywebview so upgrade your pyinstaller before proceeding
Upvotes: 2
Reputation: 113
The best way would be to use IIS(10) if you're on Windows 10.
Upvotes: 0