输出函数都定义在 pywebio.output 模块中,可以使用 from pywebio.output import * 引入。
调用输出函数后,内容会实时输出到浏览器,在应用的生命周期内,可以在任意时刻调用输出函数。
输出表格
核心代码:
python
put_table([
['Commodity', 'Price'],
['Apple', '5.5'],
['Banana', '7'],
])
完整代码:
python
from pywebio.output import put_table
data = [
["Name", "Age"],
["Zhangsan", 22],
["Lisi", 22],
["wangwu", 22],
]
put_table(data)
输出本地图片
核心代码:
python
put_image(open('/path/to/some/image.png', 'rb').read()) # local image
完整代码:
python
from pywebio.output import put_image
file_obj = open("1.jpg", "rb").read()
put_image(file_obj)
输出网络图片
核心代码:
python
put_image('http://example.com/some-image.png') # internet image
完整代码:
python
from pywebio.output import put_image
url = "https://pic.netbian.com/uploads/allimg/240118/235143-17055931030bbb.jpg"
put_image(url)
输出Markdown
核心代码:
python
put_markdown('~~Strikethrough~~')
完整代码:
python
from pywebio.output import put_markdown
text = """
# level 1
## level 2
### level 3
hello world:
- a
- b
- c
"""
put_markdown(text)
输出文件
核心代码:
python
put_file('hello_word.txt', b'hello word!')
完整代码:
python
from pywebio.output import put_file
filename = "hello.txt"
filedata = b"hello world"
put_file(filename, filedata)
输出提示内容
核心代码:
python
popup('popup title', 'popup text content')
完整代码:
python
from pywebio.output import popup
title = "popup tile"
content = "popup content"
popup(title, content)
输出消息通知
核心代码:
python
toast('New message 🔔')
完整代码:
python
from pywebio.output import toast
toast("new message")