news 2026/6/23 20:29:09

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/23 2:13:51

Claude code学习笔记(一)-环境安装claude code+ccr

ClaudeCode 是 Anthropic 推出的一款智能编程工具&#xff0c;为开发者在编码过程中提供高效协助。它通过在终端中输入自然语言指令&#xff0c;可让 Claudecode 执行多种任务。比如在代码搜索与阅读方面&#xff0c;能迅速在庞大代码库中定位关键内容&#xff0c;快速查找和理…

作者头像 李华
网站建设 2026/6/23 11:32:54

WordPress中文完全教程:从菜鸟到神人的终极指南

WordPress中文完全教程&#xff1a;从菜鸟到神人的终极指南 【免费下载链接】WordPress中文完全教程pdf下载 《WordPress中文完全教程》是一本全面而深入的电子书&#xff0c;适合从初学者到高级开发者的所有读者。从基础的安装与配置&#xff0c;到高级的主题定制与插件应用&a…

作者头像 李华
网站建设 2026/6/23 6:14:14

EmotiVoice语音合成引擎的更新日志与版本迭代规划

EmotiVoice语音合成引擎的更新日志与版本迭代规划 在虚拟主播深夜直播、AI陪护老人轻声细语&#xff0c;或是游戏NPC因剧情转折突然语气一变的瞬间——你有没有想过&#xff0c;这背后的声音是否真的“有情绪”&#xff1f;传统的文本转语音系统早已能流畅朗读&#xff0c;但那…

作者头像 李华
网站建设 2026/6/23 16:13:26

纪念日回忆录语音生成:温情科技应用

纪念日回忆录语音生成&#xff1a;温情科技应用 在一段老录音机传出的沙哑声音里&#xff0c;母亲轻声说着“生日快乐”——那是二十年前的祝福&#xff0c;如今已成绝响。我们珍藏照片、保存信件&#xff0c;却最难留住的&#xff0c;是那个熟悉的声音。当人工智能不再只是冷冰…

作者头像 李华
网站建设 2026/6/23 4:54:12

Flutter富文本渲染性能优化终极指南:长文本处理与资源回收策略

在移动应用开发领域&#xff0c;Flutter富文本渲染是构建高质量用户体验的关键技术。面对长篇文档、通讯内容或新闻内容的渲染需求&#xff0c;性能瓶颈常常成为开发者需要突破的挑战。本文将深入探讨Flutter Engine在长文本渲染中的底层实现机制&#xff0c;并分享一套完整的性…

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

Ditto剪贴板管理器架构深度解析:从用户痛点到技术实现

Ditto剪贴板管理器架构深度解析&#xff1a;从用户痛点到技术实现 【免费下载链接】Ditto Ditto is an extension to the Windows Clipboard. You copy something to the Clipboard and Ditto takes what you copied and stores it in a database to retrieve at a later time.…

作者头像 李华