吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 762|回复: 10
收起左侧

[求助] 群内小伙伴谁了解nicegui

[复制链接]
liujiayi6v 发表于 2023-12-20 22:52
大家有谁用过nicegui这个库嘛?

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

xuhuanchao 发表于 2023-12-21 09:21
[Python] 纯文本查看 复制代码
from nicegui import ui
import json
import sys
from ex4nicegui import ref_computed, effect, to_ref
from ex4nicegui.reactive import rxui

# sys.stdout = open('logs.txt', 'w')  # divert stdout to logs.txt file
# 定义响应式数据
tabArr = {'Home': '首页'}

# 头部
with ui.header(elevated=True, bordered=True).style('background-color: #3874c8;height:100px').classes(
        'items-center justify-between'):
    ui.label('HEADER')
    ui.label('AAAAAAAA')
    ui.button(on_click=lambda: left_drawer.toggle(), icon='menu').props('flat color=white')
# 左边
with ui.left_drawer(top_corner=False, bottom_corner=True).classes('w-[400px] bg-red-100') as left_drawer:
    with open('data/menu.json', 'r', encoding='utf-8') as file:
        # 读取文件内容并转换为JSON对象
        menuData = json.load(file)

    tree = ui.tree(menuData, node_key='code', label_key='label', on_select=lambda e: treeSelect(e)) \
        .style("font-size:24px;") \
        .expand(["A101"])
    tree.add_slot('default-header', '''<span :props="props"><strong>{{ props.node.label }}</strong></span>''')
# 固定显示
with ui.page_sticky(position='top-left', x_offset=20, y_offset=20):
    print("Content")
    # with ui.tabs().classes('w-full') as tabs:
    #     ui.tab("首页")
    #
    # with ui.tab_panels(tabs).classes('w-full'):
    #     with ui.tab_panel("首页"):
    #         ui.label("我是首页")


@ui.refreshable
def dynamic_tabs(names,selectTab):
    with ui.tabs() as tabs:
        for name in names:
            ui.tab(name)


    with ui.tab_panels(tabs,value=selectTab).classes("w-full"):
        for name in names:
            with ui.tab_panel(name):
                ui.label(name)

# 创建第一个页签,首页
dynamic_tabs(tabArr,"Home")


# 判断点击的节点是主节点还是子节点
def getTreeNode(code: str):
    for item in menuData:
        if int(item["level"]) == 1:
            for si in item["children"]:
                if (si["code"] == code):
                    return si
        else:
            continue


# tree点击事件
def treeSelect(e):
    ui.notify(e.value)
    item = getTreeNode(e.value)
    if item is None:
        ui.notify("请点击明细节点!")
    else:
        tabArr.update({'key': e.value,'url':item['url']})
        print(tabArr)
        dynamic_tabs.refresh(tabArr,e.value)

ui.run(title="我的工具", favicon="data/logo.ico", reload=True, native=False)

=====================menu.json===============================
[
  {"code": "A101","label":"常用工具类","level": 1,"url": "",
    "children": [
      {"code": "A10101","label": "PDF工具类","level": 2,"url": "pages/aaa.py"}
    , {"code": "A10102","label": "其他工具类","level": 2,"url": "pages/aaa.py"}
    ]
  },
  {"code": "A102","label":"组件演示","level": 1,"url": "",
    "children": [
      {"code": "A10201","label": "表格组件","level": 2,"url": "pages/aaa.py"}
      ,{"code": "A10202","label": "图表组件","level": 2,"url": "pages/aaa.py"}
    ]
  }
]

也刚学习nicegui  仅供参考
 楼主| liujiayi6v 发表于 2023-12-26 14:05
xuhuanchao 发表于 2023-12-21 09:21
[mw_shl_code=python,true]from nicegui import ui
import json
import sys

太nice了大佬~~~~~~
 楼主| liujiayi6v 发表于 2023-12-27 16:07
xuhuanchao 发表于 2023-12-21 09:21
[mw_shl_code=python,true]from nicegui import ui
import json
import sys

大佬~~nicegui用socket简单作一个聊天室,有没有现成的例子~
xuhuanchao 发表于 2023-12-29 08:19
liujiayi6v 发表于 2023-12-27 16:07
大佬~~nicegui用socket简单作一个聊天室,有没有现成的例子~

没有现成的示例
 楼主| liujiayi6v 发表于 2024-1-2 14:09
这么好用的库,感觉用的人非常的少,也不知道为啥~
moments 发表于 2024-1-8 22:34
看起来比tkinter华丽啊。
lbbas 发表于 2024-1-9 08:47
liujiayi6v 发表于 2024-1-2 14:09
这么好用的库,感觉用的人非常的少,也不知道为啥~

稍微体验了下,感觉这个使用使用浏览器作为壳来使用应该就劝退了好多人。
chenan.t 发表于 2024-1-25 09:15
打包exe用过吗?打包完运行不开窗,解释器下运行是正常的
chenan.t 发表于 2024-1-25 14:27
chenan.t 发表于 2024-1-25 09:15
打包exe用过吗?打包完运行不开窗,解释器下运行是正常的

虚拟环境下重新装后可以了。如何打开对话框选择一个本地文件获取到路径呢?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-12 10:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表