Skip to main content

tinui高级树状图

Project description

TinUITreeview

TinUI的高级树状图控件。相比于TinUI原生treeview,给拓展提供对树状图的增删改功能,以及更细化的操作实现。


使用

TinUITreeItem

树状图元素,用来表示树中的一个节点。这是一个抽象元素,包含如下信息:

  • text - 节点显示文本
  • back - 背景矩形画布 id(也是 items 字典的键)
  • te - 文字画布 id
  • sign - 展开/收起三角图标画布 id(叶节点为 None)
  • parent - 父 TinUITreeItem,根节点为 None
  • children - 子 TinUITreeItem 列表

不过,使用者并不需要在意这些细节,只需要知道这是节点元素即可。以上信息可作为属性直接获取。

TinUITreeView

TinUITreeView(
    master:BasicTinUI,
    pos: tuple,
    fg="#1a1a1a",
    bg="#f3f3f3",
    onfg="#1a1a1a",
    onbg="#eaeaea",
    oncolor="#3041d8",
    signcolor="#8a8a8a",
    width=200,
    height=300,
    font="微软雅黑 12",
    content=(
        ("one", ("1", "2", "3")),
        "two",
        ("three", ("a", ("b", ("b1", "b2", "b3")), "c")),
        "four",
    ),
    anchor="nw",
    command=None,
)

参数与TinUI原生treeview一致。

[!NOTE]

另外,tinuitreeview提供tvlighttvdark两种样式配色

[!tip]

通过TinUITreeView.uid获取控件标识符,用于TinUI面板布局。其对面板布局的响应与原生treeview一致。

get_selected()

返回选中的TinUITreeItem

add_node(text:str, parent:TinUITreeItem=None)

添加节点。

  • parent=None -> 追加到根级
  • parent=item -> 作为 item 的子节点追加

返回新建的TinUITreeItem

remove_node(item:TinUITreeItem)

删除节点及其后代。如果被删除点为亲节点最后一个节点,则亲节点变为叶子节点。

rename_node(item:TinUITreeItem, new_text:str)

重命名节点。

closs_all() / open_all()

同原生treeview

bind(sequence=None, func=None, add=None)

控件事件绑定,返回funcid

unbind(sequence, funcid=None)

控件事件解绑。


示例

# 导入必要模块...

def test(path):
    print("选中路径:", " > ".join(n.text for n in path))

root = tk.Tk()
tinui = BasicTinUI(root)
tinui.pack(fill='both',expand=True)
tree = TinUITreeView(tinui, (50, 50), command=test)

# 增
new_item = tree.add_node("新节点") # 添加到根
child = tree.add_node("子节点", parent=new_item)  # 添加到指定节点下

# 删
# tree.remove_node(child) # 同时删除所有后代,父节点若变为空则自动降级为叶节点

# 改
tree.rename_node(new_item, "renamed")

# 查
# selected = tree.get_selected() # 返回 TinUITreeItem 或 None
# print("当前选中:", selected)

# 展开/折叠
tree.close_all()
root.after(2000, tree.open_all) # 2秒后展开所有节点

rp = ExpandPanel(tinui, tree.uid)
def on_resize(e):
    rp.update_layout(5, 5, e.width-5, e.height-5)
tinui.bind("<Configure>", on_resize)

root.mainloop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinuitreeview-1.2.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinuitreeview-1.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file tinuitreeview-1.2.0.tar.gz.

File metadata

  • Download URL: tinuitreeview-1.2.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tinuitreeview-1.2.0.tar.gz
Algorithm Hash digest
SHA256 fbde0df90afb95aa5e80ef0e552ce3bbe6bae72373f33e77a187e2f15d78eef6
MD5 c6657962affe5a3c16cf9c55ba590fc0
BLAKE2b-256 e50cb5fcc671ff68285a285a9c3dfa412536e9d8a1e2524b7a995f6239316b3a

See more details on using hashes here.

File details

Details for the file tinuitreeview-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: tinuitreeview-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tinuitreeview-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a79cf4e8e613e18970ba6b35a856c118e20e218dcf2e260349cb39322bca551e
MD5 b541ed048f90ee62b7f410b0df8cd217
BLAKE2b-256 81503007604cc0d58127212664229ef7866ba109f490dc2c4f23070bb3cb01aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page