gpt4 book ai didi

python - 如何在ttk treeview sun树下显示内容

转载 作者:行者123 更新时间:2023-12-01 07:49:13 25 4
gpt4 key购买 nike

我有这几行代码,我希望我的性别内容显示在与名称同一行的 TreeView 子树下,但它显示在子树之后的新行上。

希望它显示如下例:

弗雷德·马

MAVIS 女

弗雷德·其他

在子树下的同一行上,但无法实现这一点。

欢迎您提出建议来实现这一目标。

from tkinter import ttk
import tkinter as tk


root = tk.Tk()
root.geometry("1200x680+50+20")


tree = ttk.Treeview(root)
############
tree.config(columns=("col1","col2","col3"))


#SUb treeview
style = ttk.Style(root)
style.configure("Treeview", rowheight=30)
tree.configure(style="Treeview")


tree.heading("#1", text="DOB")
tree.heading("#2", text="SCHOOL")
tree.heading("#3", text="GENDER")


tree.insert("", "0", "item1", text="Names",)
tree.insert("", "1", "item2", text="Names")


tree.set("item1", "#1", ["2019-05-25"])
tree.set("item1", "#2", ["HARVARD"])


#sub tree using item attribute to achieve that
tree.insert("item1", "1", text="FRED")
tree.insert("item1", "1", text="MAVIS")
tree.insert("item1", "1", text="BRIGHT")


tree.insert("", tk.END, values=("", "", "MALE"))
tree.insert("", tk.END, values=("", "", "OTHER"))
tree.insert("", tk.END, values=("", "", "FEMALE"))




tree.pack(fill=tk.BOTH, expand=True)


root.mainloop()

最佳答案

要实现你想要的,你可以替换它:

tree.set("item1", "#1", ["2019-05-25"])
tree.set("item1", "#2", ["HARVARD"])


#sub tree using item attribute to achieve that
tree.insert("item1", "1", text="FRED")
tree.insert("item1", "1", text="MAVIS")
tree.insert("item1", "1", text="BRIGHT")


tree.insert("", tk.END, values=("", "", "MALE"))
tree.insert("", tk.END, values=("", "", "OTHER"))
tree.insert("", tk.END, values=("", "", "FEMALE"))

这样:

tree.insert("item1", "end", text="FRED", values=("2019-05-25", "HARVARD", "MALE"))
tree.insert("item1", "end", text="MAVIS", values=("2019-05-25", "HARVARD", "OTHER"))
tree.insert("item1", "end", text="BRIGHT", values=("2019-05-25", "HARVARD", "FEMALE"))

关于python - 如何在ttk treeview sun树下显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56308759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com