Skip to main content

TinUITreeview

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


使用

TinUITreeItem

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

  • text - 节点显示文本
  • back - 背景矩形画布 id(也是 items 字典的键)
  • te - 文字画布 id
  • sign - 展开/收起三角图标画布 id(叶节点为 None)
  • parent - 亲节点的弱引用ReferenceType[TinUITreeItem],根节点为 None
  • children - 子 TinUITreeItem 列表
  • checkable - 是否为可选值
  • check_state - 值选中状态:0=未选,1=全选,2=半选
  • checkitems - (outline, fill, text),均为文本元素

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

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一致。

get_selected()

返回选中的TinUITreeItem。

select_node

def select_node(self, values:List[str]) -> bool:

选择节点。

  • values - 以文本形式描述选择节点的路径

最终选到则返回true。途中所有可选中节点均会被展开。

add_node

def add_node(
    self,
    text: str,
    parent: TinUITreeItem|None = None,
    checkable: bool = False,
    check_state: bool = False,
) -> TinUITreeItem:

添加节点。

  • parent=None -> 追加到根级
  • parent=item -> 作为 item 的子节点追加
  • checkable - 是否值可选
  • check_state - 是否值选中

返回新建的TinUITreeItem。

remove_node(item:TinUITreeItem)

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

rename_node(item:TinUITreeItem, new_text:str)

重命名节点。

closs_all() / open_all()

同原生treeview。

check_change(item: TinUITreeItem, state=None)

更改item的值选状态。

状态直接传递传递给子节点,可能会影响亲节点的值选状态。

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("新节点", checkable=True) # 添加到根
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()

Metadata

Release files for tinuitreeview 1.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinuitreeview 1.4.2
File Size Uploaded Provenance Actions
tinuitreeview-1.4.2.tar.gz 17.2 kB Without provenance Details for tinuitreeview-1.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tinuitreeview 1.4.2
File Interpreter ABI Platform Actions
tinuitreeview-1.4.2-py3-none-any.whl Python 3 none any Details for tinuitreeview-1.4.2-py3-none-any.whl

Total release size: 33.2 kB

Release files / tinuitreeview-1.4.2.tar.gz

Download URL tinuitreeview-1.4.2.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8cadc2141df278547891afad003379dc3aa6d9995ad14a9dbbcef8b1eb91dc65
BLAKE2b-256 checksum
How to use checksums
805899af5912bfaeccba614e92c34205326c5262cf6fcb1acaf13656f99b481c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / tinuitreeview-1.4.2-py3-none-any.whl

Download URL tinuitreeview-1.4.2-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3e87fd1e6d36190ee322776208605323b72f83e7f4ec20386197f2d18aa5dbf
BLAKE2b-256 checksum
How to use checksums
c3ae20d0c7f413730b35df0892d1ff0e0849210d9460146d725a5bd51cf84388
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Security for tinuitreeview 1.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page