群内小伙伴谁了解nicegui
大家有谁用过nicegui这个库嘛? from nicegui import uiimport 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- 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仅供参考
xuhuanchao 发表于 2023-12-21 09:21
from nicegui import ui
import json
import sys
太nice了大佬~~~~~~ xuhuanchao 发表于 2023-12-21 09:21
from nicegui import ui
import json
import sys
大佬~~nicegui用socket简单作一个聊天室,有没有现成的例子~ liujiayi6v 发表于 2023-12-27 16:07
大佬~~nicegui用socket简单作一个聊天室,有没有现成的例子~
没有现成的示例 这么好用的库,感觉用的人非常的少,也不知道为啥~ 看起来比tkinter华丽啊。 liujiayi6v 发表于 2024-1-2 14:09
这么好用的库,感觉用的人非常的少,也不知道为啥~
稍微体验了下,感觉这个使用使用浏览器作为壳来使用应该就劝退了好多人。 打包exe用过吗?打包完运行不开窗,解释器下运行是正常的 chenan.t 发表于 2024-1-25 09:15
打包exe用过吗?打包完运行不开窗,解释器下运行是正常的
虚拟环境下重新装后可以了。如何打开对话框选择一个本地文件获取到路径呢?
页:
[1]
2