拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 不用H5,直接使用pywebio模块实作网页

不用H5,直接使用pywebio模块实作网页

白鹭 - 2022-02-25 2062 0 0

pywebio最大的好处就是可以像撰写终端脚本一样撰写web网页,通过提供一系列的互动函式在浏览器的层面上获取用户的输入与输出,

【阅读全文】

file

pycharm 编辑器下运行效果

file

ipython 编辑器下运行效果

file

安装 python web 插件

pip3 install -U pywebio

汇入相关模块

from pywebio.input import *

from pywebio.output import *

from pywebio import start_server

输入型信息提交

    def validate_age(age):
        if age < 1:
            return "年龄太小了"
        elif age > 120:
            return "年龄太大了"
        else:
            pass

    name = input('请输入你的姓名:')
    age = input('请输入你的年龄:', type=NUMBER, validate=validate_age, help_text='必须输入1到120之间的数字')
    sex = select("选择性别:", ['男', '女'])

    rsrv = textarea("请填写备注资讯", rows=3, placeholder='备注资讯')

    # todo 根据提交的信息处理业务
    print(name, age, sex, rsrv)

输出型信息提交


put_text('输出输入的信息:')
    put_table(
        tdata=https://www.cnblogs.com/lwsbc/p/[
            ['序号', '姓名', '年龄', '性别', '备注'],
            [1, name, age, sex, rsrv]
        ]
    )
    put_table(
        tdata=https://www.cnblogs.com/lwsbc/p/[
            ['序号', '姓名', '年龄', '性别', '备注'],
            [1, 'Python 集中营', 12, '未知', '我是一个专注于知识分享的公众号']
        ]
    )
    put_html(
        '<font color="green">公众号[Python 集中营],我是一个专注于知识分享的公众号!</font>'
    )
    arraies = [['列名1', '列名2', '列名3', '列名4', '列名5', '列名6', '列名7', '列名8', '列名9', '列名10'],
               ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
               ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
               ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
               ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
               ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'],
               ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'o'], ]
    put_table(
        tdata=https://www.cnblogs.com/lwsbc/p/arraies
    )

start_server 调起服务

if __name__ == '__main__':
    '''start_server 函式启动web应用'''
    start_server(
        applications=[app_exec],
        reconnect_timeout=3000,
        debug=True,
        auto_open_webbrowser=True,
        remote_access=True
    )

file

【往期精选】

python回呼函式能做什么?

解决pyinstaller打包程序中外部资源无法加载的问题 ...

pyqt5做了一个二维码生成器,已打包成exe可执行程序...

如何在控制台实作一个资料管理系统(包括MYSQL数据库的增删改查)

自制档案格式转换器,支持 .txt/.xlsx/.csv格式转换...

欢迎关注作者公众号【Python 集中营】,专注于后端编程,每天更新技术干货,不定时分享各类资料!
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *