Prerequisite:
This tutorial is part of the Flask CKEditor Project Series.
python -m venv venv
venv\Scripts\activate
pip install ttkbootstrap pywebview pyinstaller
Then all I need to do is create a Python file below.
What is PyWebView?
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
# Create TTKbootstrap window
root = ttk.Window(themename="darkly")
root.geometry("400x200")
root.title("Launcher")
# Create a button with open_app function
btn = ttk.Button(root, text="Open Web App", bootstyle=SUCCESS, command=open_app)
btn.pack(pady=50)
Here, I only create a button, "Open Web App," and when I click the button, it will pop up the webview window in step 2 below.import webview
def open_app():
# Create a new window titled "How App"
# and load the web application URL inside it
webview.create_window('How App', 'https://howapp.pythonanywhere.com/')
# Start the pywebview event loop (opens and runs the window)
webview.start()
🎁 Get Your FREE Flask Cheat Sheet
Get more Flask, Python automation, Docker, and HTMX tutorials delivered to your inbox.
✓ Practical coding tutorials
✓ Automation tips for SMEs
✓ New project ideas and templates
Download my FREE Flask Cheat Sheet (PDF)
pyinstaller --onefile --noconsole `
--hidden-import=webview.platforms.edgechromium `
--hidden-import=webview.platforms.winforms `
webview_tkinter.pyWhy do I need to hide the above files? Both Flaskwebgui and pywebview are popular choices for wrapping a Flask application into a desktop-like experience, but they achieve this in fundamentally different ways.
FlaskWebGui
Flaskwebgui is designed specifically for "converting" an existing web application into a desktop application with minimal changes to your code.
Core Approach: It works by starting your Flask server in a background thread and then launching a standard browser (usually Chrome in "app mode") to point to your local Flask URL.
Best For: Developers who want their web app to look and behave like a desktop app with the least amount of effort.
If it works in your web browser, it will work in FlaskWebGui. Key Pros:
Ease of Use: You can often "convert" an app with just a few extra lines of code.
Compatibility: Because it uses a real browser, you won't encounter issues where specific JavaScript or CSS features fail to render, which can sometimes happen in embedded webview engines.
No New Logic: You don't need to learn any specific API for window management or bridging Python and JavaScript.
Key Cons:
External Dependency: It relies on the user having a compatible browser (like Chrome/Edge) installed on their system.
Browser-like Behavior: It provides a browser-in-app experience rather than a "native" desktop window.
Pywebview
Pywebview is a more robust, framework-agnostic wrapper that creates a native GUI window using the OS's native webview engine (e.g., Edge/WebView2 on Windows, WebKit on macOS).
Core Approach: It creates an actual native window and embeds a lightweight web renderer inside it.
It doesn't rely on an external browser like Chrome; it uses the system’s built-in web component. Best For: Developers who want a "native" desktop feel, tighter integration between Python and the frontend, and smaller distribution sizes.
Key Pros:
Native Integration: It provides a true native window and supports native features like menus, file dialogs, and message boxes.
Two-Way Bridge: It features a built-in bridge that allows for direct communication between Python and your frontend (JavaScript) without needing HTTP requests.
Standalone Feel: The user doesn't need to have Chrome or another browser installed; the app uses the system's native engine.
Key Cons:
Complexity: It may require more configuration to get right, especially regarding cross-platform engine dependencies (e.g., ensuring the right WebKit or WebView2 components are present).
Renderer Differences: Since it uses the OS's native webview, you might occasionally encounter inconsistencies where complex JavaScript or modern CSS features render slightly differently than they do in Chrome.
Which should you choose?
Choose FlaskWebGui if you already have a Flask app and simply want it to open in its own window without worrying about compatibility issues or learning new APIs.
Choose Pywebview if you want a more professional, standalone desktop application that feels integrated into the OS or if you need to use the powerful Python-to-JavaScript bridge to interact deeply between your backend and frontend.
About the Author
Kelvin Loh is a Python developer focused on Flask, desktop applications, and business automation solutions. He shares practical tutorials and real-world coding projects to help developers and small businesses build useful applications.





Comments