DEV Community

loading...

Flask for creating desktop apps (no Electronjs)

climentea profile image Alin Climente Updated on ・1 min read

Yep, you read that well desktop applications using Python and web technologies.

First, install this library:

pip install flaskwebgui
Enter fullscreen mode Exit fullscreen mode

Bellow you have the usage of flaskwebgui:

#main.py

from flask import Flask  
from flask import render_template
from flaskwebgui import FlaskUI # import FlaskUI

app = Flask(__name__)
ui = FlaskUI(app, width=500, height=500) # add app and parameters


@app.route("/")
def hello():  
    return render_template('index.html')

@app.route("/home", methods=['GET'])
def home(): 
    return render_template('some_page.html')


if __name__ == "__main__":
    # app.run() for debug
    ui.run()

Enter fullscreen mode Exit fullscreen mode

Alternatively, next to main.py create a file called gui.py and add the following contents:

#gui.py

from flaskwebgui import FlaskUI
from main import app

FlaskUI(app, width=600, height=500).run()
Enter fullscreen mode Exit fullscreen mode

Next start the application with:

python main.py 
#or
python gui.py #in case you created gui.py 
Enter fullscreen mode Exit fullscreen mode

Application will start chrome in app mode, flask will be served by waitress.

And that's all!

Discussion (0)

pic
Editor guide