Skip to main content

How to Build a Contact Form for SME Systems with Flask CKEditor (Part 7)


This Python script creates a simple desktop launcher using Tkinter with ttkbootstrap for modern styling. The application displays a window with a button that, when clicked, opens a Flask-based web application in a native window using pywebview. This approach combines a lightweight desktop interface with a web-powered backend, making it easy to deploy existing web apps as desktop applications.

Preliminary 
Before I begin, please activate the virtual environment and install the required dependencies.
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?

In fact, PyWebView is a lightweight Python library that lets me display web content (HTML, CSS, JavaScript, or even a full Flask app) inside a native desktop window. Since I have deployed Flask on PythonAnywhere in the previous tutorial. Therefore, all I need for this project is to embed the entire browser into the window.

Step 1: Set up a desktop launcher window
Before I set up the webview window, I created a launcher window as follows.


I chose "ttkBootstrap" as my GUI. My theme is "darkly," and the window dimensions are 400x200.
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.


Step 2: Embed the webview within the desktop window
Now I will embed the browser window with an HTML link "https://howapp.pythonanywhere.com/" inside the webview window, and here is my code:
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()
Next, when the function is called, it will pop up a new webview window as shown below:




Step 3: Package the ttkbootstrap desktop app
Before it can be distributed to the user to use, I need to package the desktop app. Therefore, in PowerShell, I will input the following code:
pyinstaller --onefile --noconsole `
--hidden-import=webview.platforms.edgechromium `
--hidden-import=webview.platforms.winforms `
webview_tkinter.py
Why do I need to hide the above files? 
This is because in PyInstaller, a hidden import is a module that my app uses, but PyInstaller cannot detect automatically. Therefore, I will tell PyInstaller, “Hey, include these modules even if you didn’t detect them.”

So, overall, the above code means execute the PyInstaller to pack everything into one single executable file and hide the terminal and relevant imports, as I have mentioned above.

Final wrap-up:
In summary, PyWebview provides a simple way to turn your web-based application into a desktop experience by displaying it inside a native window. When combined with ttkbootstrap, you can create a clean Tkinter interface that acts as a launcher while your main application runs as a web app. This setup is especially useful if you already have a Flask project, allowing you to reuse your existing code while delivering it in a desktop-friendly format.

Comments

Popular Posts

How to Design a Location Tracking Module for Desktop Business Systems Using Python?

This tutorial will show you how to create an interactive map application that allows users to input geographic coordinates and visualize locations on an interactive map using Python's Tkinter GUI framework enhanced with TTKBootstrap styling and the TkinterMapView widget.  Preliminary   Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies. python -m venv venv venv\Scripts\activate pip install ttkbootstrap tkintermapview As usual, we need to import the relevant module and set the root values from tkinter import * import ttkbootstrap as tb import tkintermapview from ttkbootstrap.dialogs import Messagebox root = tb.Window(themename='darkly') root.title('Find My Map') root.geometry("1200x1200") I would like to divide it into three sections.  a) Input Panel Layout,  The headers are mainly a label with a map emoji.  The main layout contains labels and input fields for latitude and longitude, ...

How to Build a Contact Form for SME Systems with Flask CKEditor (Part 3)

  In the previous tutorial, I used TinyDB as our storage solution to keep application data in a simple JSON-based format. While TinyDB is lightweight and easy to use, many web applications require a more structured and scalable database system. In this tutorial, we will switch to SQLite , a powerful relational database that integrates well with Python and web frameworks. By using SQLite, you will learn how to store, manage, and query data in a more structured way for real-world applications. Preliminary Before I begin, please activate the virtual environment and install the required dependencies. Since SQLite is part of the Python standard library, it is pre-installed. python -m venv venv venv\Scripts\activate pip install flask Then, we need to set up the file and folder structure, as below: Question 1: What is SQLite? SQLite is a lightweight, serverless relational database that stores data in a single file on your computer. Unlike traditional database systems, it does ...

How to build a Desktop Business System for Audiobook Workflow Management with Python?

In this tutorial, we will build a simple audiobook player using Python and CustomTkinter. You will learn how to convert text into speech using gTTS and play it with PyGame. We will also implement play, pause, and stop controls, like those in a real audio player. By the end, you will have a clean and functional desktop audiobook app. Preliminary   Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies. python -m venv venv venv\Scripts\activate pip install customtkinter pillow gTTS pygame CTkMessagebox pypdf Then, the following steps include setting up the file structure, app.py, and two additional folders: the uploads and media folders. The media folder contains the icons necessary to build the app; there are read, pause, and stop icons, as shown on the diagram. Step 1: Build up the app interface I have 4 sections here: the header, upload area, text body, and button group.  (a) The header—this section is basicall...