news 2026/6/22 4:07:57

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/21 7:36:14

EmotiVoice与RVC技术融合的可能性探讨

EmotiVoice与RVC技术融合的可能性探讨 在虚拟主播的直播画面中&#xff0c;一个卡通角色正激动地讲述着冒险故事——语调起伏、情绪饱满&#xff0c;声音既不像机械朗读&#xff0c;也不完全是真人配音。这背后&#xff0c;正是AI语音技术从“能说话”迈向“会表达”的关键跃迁…

作者头像 李华
网站建设 2026/6/20 7:15:01

BLIP和BLIP2解析

1. BLIP BLIP 是一种多模态 Transformer 模型&#xff0c;主要针对以往的视觉语言训练 (Vision-Language Pre-training, VLP) 框架的两个常见问题&#xff1a; 模型层面&#xff1a;大多数现有的预训练模型仅在基于理解的任务或者基于生成的任务方面表现出色&#xff0c;很少有…

作者头像 李华
网站建设 2026/6/17 14:34:57

百度网盘提取码智能获取实用指南:轻松完成资源下载

还在为百度网盘分享链接的提取码而烦恼吗&#xff1f;每次遇到加密分享都要花费大量时间在各种平台间来回切换寻找密码&#xff1f;今天给大家介绍一款实用工具——baidupankey智能提取码获取工具&#xff0c;让你从此告别繁琐的手动查找&#xff0c;快速轻松获取提取码&#x…

作者头像 李华
网站建设 2026/6/15 20:37:52

突破性AI模型部署方案:从资源密集型到轻量化智能优化策略

突破性AI模型部署方案&#xff1a;从资源密集型到轻量化智能优化策略 【免费下载链接】FastChat An open platform for training, serving, and evaluating large language models. Release repo for Vicuna and Chatbot Arena. 项目地址: https://gitcode.com/GitHub_Trendi…

作者头像 李华
网站建设 2026/6/20 14:37:33

终极指南:Moq框架在复杂系统中的高级模拟技巧

终极指南&#xff1a;Moq框架在复杂系统中的高级模拟技巧 【免费下载链接】VPet 虚拟桌宠模拟器 一个开源的桌宠软件, 可以内置到任何WPF应用程序 项目地址: https://gitcode.com/GitHub_Trending/vp/VPet 在现代软件开发中&#xff0c;单元测试已成为保障代码质量的基石…

作者头像 李华
网站建设 2026/6/18 23:21:35

虎贲等考 AI:学术星河的智能领航者,以科技解锁科研新次元

“科研之路迷雾重重&#xff0c;选题、数据、写作全是难关&#xff1f;”&#x1f914;“传统科研模式效率低下&#xff0c;想突破却找不到方向&#xff1f;”&#x1f4a5;“学术星河浩瀚无垠&#xff0c;谁能带你精准导航&#xff0c;解锁科研新可能&#xff1f;”&#x1f6…

作者头像 李华