Backend Development 3 min read

Building a Simple Web Calculator with PyWebIO and Packaging with PyInstaller

This tutorial shows how to create a lightweight web-based calculator using the Python library PyWebIO, covering installation, full source code, local execution, and optional packaging into a standalone executable with PyInstaller for easy distribution.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Building a Simple Web Calculator with PyWebIO and Packaging with PyInstaller

The article demonstrates how to create a simple web-based calculator using the Python library pywebio , showing installation commands, the full source code, and how to run it locally.

Installation: pip install pyinstaller and pip install pywebio .

Main program code:

from pywebio import start_server
from pywebio.output import *
from pywebio.pin import *

def calc(exp):
    try:
        return f"{exp}={eval(exp)}"
    except:
        return f"{exp}:表达式不正确"

def refresh(exp):
    out = calc(exp)
    with use_scope("aa", clear=True):
        put_text(out)

def webmain():
    put_markdown("## 简易计算器 \n 输入计算表达式:")
    put_input("res")
    put_buttons(["计算"], lambda _: refresh(pin.res))

start_server(webmain, host="127.0.0.1", port=2022)

Running the script and opening http://127.0.0.1:2022/ in a browser displays the calculator interface.

Deployment options include copying the script to a server, or packaging it into a standalone executable with PyInstaller using commands such as pyinstaller -F main.py -i icon.ico and handling the generated main.exe .

The guide concludes that pywebio enables rapid development of small interactive tools, and pyinstaller simplifies distribution.

PythontutorialpyinstallerpywebioWeb Calculator
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.