Developing Interactive Web Applications with Python

Interactive web apps are useful for things like making a survey page, a polling system, an information gathering form, uploading files, etc. Because the web pages are visual, they can also be used as a graphical interface application without a server.

If you have such development needs, it's really easy to use Python.

With the help of PyWebIO (pip install pywebio), you can enter information on web pages in minutes, see the following motion picture.


The page above, too, uses just these 6 lines of code.

from pywebio.input import *

input("This is a simple text input")
select("This is a drop down menu", ['Option1', 'Option2'])
checkbox("Multiple Choices!", options=["a",'b','c','d'])
radio("Select any one", options=['1', '2', '3'])
textarea('Text Area', rows=3, placeholder='Multiple line text input')

To make the web page output the desired information is also very simple, the code is as follows, the function function has made the relevant comments, you can easily read and understand.

from pywebio.output import *
from pywebio import session

# Display plain text on web pages
put_text("Hello friend!")

# Displaying tables on the web
    ['Object', 'Unit'],
    ['A', '55'],
    ['B', '73'],

# MarkDown is displayed on the page

# The link to download the file is displayed on the web page
put_file('output_file.txt', b'You can put anything here')

# Display images on the web
put_image(open('python_logo.png', 'rb').read())

# Display pop-ups on web pages
popup('popup title', 'popup text content')

# Keep the callback is open, otherwise the program will exit after the page is displayed

The results of the run are as follows.


Related articles