DEV Community

Alin Climente
Alin Climente

Posted on • Edited on

7 2

Flask for creating desktop apps (no Electronjs)

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!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
rizwan486 profile image
Rizwan Hasan

It would become more awesome if you've added screenshots.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay