Python私教张大鹏 PyWebIO输出表格,网络图片,Markdown,代码片段等

输出函数都定义在 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")
相关推荐
IT=>小脑虎3 分钟前
PHP零基础衔接进阶知识点【详解版】
开发语言·学习·php
ling-457 分钟前
Linux-day09 11
linux·运维·服务器
zbguolei9 分钟前
Debian提示:“用户名” 不是 sudoers 文件
linux·服务器·debian
dagouaofei11 分钟前
2026 年工作计划 PPT 制作方式对比:AI 与传统方法差异
人工智能·python·powerpoint
虚拟搬运工15 分钟前
xformers造成comfyu启动失败
python·comfyui
Hello.Reader16 分钟前
PyFlink DataStream Operators 算子分类、函数写法、类型系统、链路优化(Chaining)与工程化踩坑
前端·python·算法
Learner27 分钟前
Python函数
开发语言·python
万行32 分钟前
机器学习&第五章生成式生成器
人工智能·python·算法·机器学习
_李小白33 分钟前
【Android FrameWork】延伸阅读:AMS 的 handleApplicationCrash
android·开发语言·python
zhangdawei8381 小时前
英伟达GB200,GB300和普通服务器如dell R740xd有什么区别?
运维·服务器·人工智能