news 2026/6/10 3:38:26

NiceGUI之Button操作(ElementPlus组件库)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
NiceGUI之Button操作(ElementPlus组件库)

1、效果预览

2、代码

fromniceguiimportapp,ui ui.add_body_html(''' <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" /> <script defer src="https://unpkg.com/element-plus"></script> ''')app.config.vue_config_script+=''' app.use(ElementPlus); '''SHARE=""" <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="m679.872 348.8-301.76 188.608a127.8 127.8 0 0 1 5.12 52.16l279.936 104.96a128 128 0 1 1-22.464 59.904l-279.872-104.96a128 128 0 1 1-16.64-166.272l301.696-188.608a128 128 0 1 1 33.92 54.272z"></path></svg> """TURNOFF=""" <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M329.956 257.138a254.862 254.862 0 0 0 0 509.724h364.088a254.862 254.862 0 0 0 0-509.724zm0-72.818h364.088a327.68 327.68 0 1 1 0 655.36H329.956a327.68 327.68 0 1 1 0-655.36"></path><path fill="currentColor" d="M329.956 621.227a109.227 109.227 0 1 0 0-218.454 109.227 109.227 0 0 0 0 218.454m0 72.817a182.044 182.044 0 1 1 0-364.088 182.044 182.044 0 0 1 0 364.088"></path></svg> """SWITCH=""" <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M118.656 438.656a32 32 0 0 1 0-45.248L416 96l4.48-3.776A32 32 0 0 1 461.248 96l3.712 4.48a32.064 32.064 0 0 1-3.712 40.832L218.56 384H928a32 32 0 1 1 0 64H141.248a32 32 0 0 1-22.592-9.344M64 608a32 32 0 0 1 32-32h786.752a32 32 0 0 1 22.656 54.592L608 928l-4.48 3.776a32.064 32.064 0 0 1-40.832-49.024L805.632 640H96a32 32 0 0 1-32-32"></path></svg> """withui.row():ui.markdown("##### 不同颜色的按钮:")withui.element('el-button').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="success"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="info"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="warning"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="danger"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### 带图标+文字按钮:")ui.link('图标合集','https://element-plus.org/zh-CN/component/icon#icon-collection')withui.element('el-button').props('type="danger"').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(SHARE,sanitize=False).style('margin-right:5px')ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="warning"').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(TURNOFF,sanitize=False).style('margin-right:5px')ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="info"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-icon').props('size="18"'):ui.html(SWITCH,sanitize=False).style('margin-left:8px')withui.element('el-button').props('type="success"').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(TURNOFF,sanitize=False).style('margin-right:5px')ui.html('Element Plus button',sanitize=False)withui.element('el-icon').props('size="18"'):ui.html(SWITCH,sanitize=False).style('margin-left:8px')withui.row():ui.markdown("##### plain样式按钮:")withui.element('el-button').props('plain').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('plain').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('plain').props('type="success"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('plain').props('type="info"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('plain').props('type="warning"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('plain').props('type="danger"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### round样式按钮:")withui.element('el-button').props('round').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('round').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('round').props('type="success"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('round').props('type="info"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('round').props('type="warning"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### 图标按钮:")withui.element('el-button').props('type="info"').props('circle').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(SHARE,sanitize=False)withui.element('el-button').props('type="primary"').props('circle').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(TURNOFF,sanitize=False)withui.element('el-button').props('type="danger"').props('circle').on('click',lambda:ui.notify('Hi!')):withui.element('el-icon').props('size="18"'):ui.html(SWITCH,sanitize=False)withui.row():ui.markdown("##### 禁用按钮:")withui.element('el-button').props('disabled').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('disabled').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### 链接按钮:")withui.element('el-button').props('link').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('link').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### 按钮组:")withui.element('el-button-group'):withui.element('el-button').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="primary"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### 不同大小按钮:")withui.element('el-button').props('type="primary"').props('size="small"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="info"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.element('el-button').props('type="success"').props('size="large"').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)withui.row():ui.markdown("##### loading按钮:")withui.element('el-button').props('loading').on('click',lambda:ui.notify('Hi!')):ui.html('Element Plus button',sanitize=False)asyncdefchange_loading(bt,text):importasyncio# 设置为加载状态bt.props(":loading=true")# 修改按钮文本为"加载中..."text.content="加载中..."awaitasyncio.sleep(5)# 取消加载状态bt.props(":loading=false")# 修改按钮文本为"点击后loading 5s"text.content="点击后loading 5s"# 设置按钮文案withui.element('el-button').props('type="primary"')asf:bt_text_element=ui.html('点击后loading 5s',sanitize=False)# 绑定点击事件f.on('click',lambda:change_loading(f,bt_text_element))ui.run(port=8888)
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/9 15:46:43

EmotiVoice如何处理诗歌、歌词等韵律文本?

EmotiVoice如何处理诗歌、歌词等韵律文本&#xff1f; 在有声书平台深夜自动合成千首古诗朗诵的今天&#xff0c;在虚拟歌姬用AI“演唱”原创国风歌词的当下&#xff0c;我们不得不承认&#xff1a;语音合成早已不再满足于“把字读出来”。真正的挑战在于——如何让机器读懂诗句…

作者头像 李华
网站建设 2026/6/10 14:52:09

公共图书馆有声服务升级:基于EmotiVoice

公共图书馆有声服务升级&#xff1a;基于 EmotiVoice 的智能语音实践 在数字化浪潮席卷公共文化服务体系的今天&#xff0c;公共图书馆的角色正悄然转变——从“藏书楼”走向“知识客厅”。越来越多读者不再满足于静态的文字阅读&#xff0c;而是期待更自然、更具沉浸感的信息获…

作者头像 李华
网站建设 2026/6/9 15:50:34

粤语、四川话等地方言语音生成进展汇报

粤语、四川话等地方言语音生成进展汇报 在智能语音助手逐渐走进千家万户的今天&#xff0c;一个现实问题日益凸显&#xff1a;为什么大多数TTS系统一开口还是“普通话腔”&#xff1f;即便是在广州、成都这样的城市&#xff0c;用户期待听到的是地道的粤语“早晨啊&#xff01…

作者头像 李华
网站建设 2026/6/9 19:34:19

Java线程学习笔记:从基础到实践的核心梳理在Java开发中,线程是实现并发编程的核心基础,也是面试高频考点。随着多核处理器的普及,高效的线程管理能力成为开发者必备技能。这段时间通过课程学习和实践

Java IO学习笔记&#xff1a;从字节流到NIO的完整梳理在Java开发中&#xff0c;输入输出&#xff08;IO&#xff09;是与外部设备进行数据交互的核心技术&#xff0c;无论是读取文件、网络通信还是操作数据库&#xff0c;都离不开IO的支持。IO技术看似基础却贯穿开发全流程&…

作者头像 李华
网站建设 2026/6/10 13:59:58

数据可视化神器TimelineJS:零基础打造品牌故事时间轴

数据可视化神器TimelineJS&#xff1a;零基础打造品牌故事时间轴 【免费下载链接】TimelineJS 项目地址: https://gitcode.com/gh_mirrors/tim/TimelineJS 还在为品牌宣传材料枯燥乏味而发愁&#xff1f;想让你的品牌发展历程跃然纸上&#xff1f;今天带你解锁数据可视…

作者头像 李华