如何检测TreeView列是否为空

时间:2018-07-27 16:23:43

标签: tkinter treeview

我要使用此功能检查treeview len`的tree.get_children(). Am able to check if the is no content in the treeview with列是否为空。

def test():
    b = tree.get_children()

    if len(b) == 0:
        print("empty")
    else:

        print("data in it")

但是我要做的是使用此功能检查是否没有任何内容插入列1下。但输出错误

  

IndexError:元组索引超出范围

def test_2():
    for child in tree.get_children():
        bd = tree.item(child, "values")[1]
        th = tree.item(child, "values")[0]

        if bd == 0:
            print("column 2 empty")
        else:
            print(bd)
            print("fffh\t" + th)






root = tk.Tk()
root.geometry("400x400")


tree = ttk.Treeview( columns=("col1", "col2"), show="headings")
tree.heading("#1", text="DATE")
tree.heading("#2", text="TOTAL AMOUNT")

tree.column("#1", stretch=tk.NO, minwidth=80, width=150)
tree.column("#2", stretch=tk.NO, minwidth=45, width=150)

tree.insert("", tk.END, values=("dsjjj"))
tree.pack()

b = tk.Button(root, text="axample", command=test_2)
b.pack()

root.mainloop()

0 个答案:

没有答案