pywebio最大的好處就是可以像撰寫終端腳本一樣撰寫web網頁,通過提供一系列的互動函式在瀏覽器的層面上獲取用戶的輸入與輸出,
【閱讀全文】

pycharm 編輯器下運行效果

ipython 編輯器下運行效果

安裝 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/archive/2021/12/30/[
['序號', '姓名', '年齡', '性別', '備注'],
[1, name, age, sex, rsrv]
]
)
put_table(
tdata=https://www.cnblogs.com/lwsbc/archive/2021/12/30/[
['序號', '姓名', '年齡', '性別', '備注'],
[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/archive/2021/12/30/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
)

【往期精選】
python回呼函式能做什么?
解決pyinstaller打包程序中外部資源無法加載的問題 ...
pyqt5做了一個二維碼生成器,已打包成exe可執行程式...
如何在控制臺實作一個資料管理系統(包括MYSQL資料庫的增刪改查)
自制檔案格式轉換器,支持 .txt/.xlsx/.csv格式轉換...
歡迎關注作者公眾號【Python 集中營】,專注于后端編程,每天更新技術干貨,不定時分享各類資料!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/398427.html
標籤:其他
上一篇:Golang專案的配置管理——Viper簡易入門配置
下一篇:>Bagging
