【问题标题】:How add button in treeview?如何在树视图中添加按钮?
【发布时间】:2017-10-07 19:14:38
【问题描述】:

我使用 tkinter 库在 python 3.6.4 中编写了一个程序

from tkinter import ttk
import tkinter

root = tkinter.Tk()

tree = ttk.Treeview(root)

tree["columns"]=("one","two")
tree.column("one", width=100 )
tree.column("two", width=100)
tree.heading("one", text="coulmn A")
tree.heading("two", text="column B")

tree.insert("" , 0,    text="Line 1", values=("1A","1b"))

id2 = tree.insert("", 1, "dir2", text="Dir 2")
tree.insert(id2, "end", "dir 2", text="sub dir 2", values=("2A","2B"))

##alternatively:
tree.insert("", 3, "dir3", text="Dir 3")
tree.insert("dir3", 3, text=" sub dir 3",values=("3A"," 3B"))

tree.pack()
root.mainloop()

我想在树视图上添加按钮,但我不怎么做。

【问题讨论】:

标签: python tkinter add


【解决方案1】:

@kogito 的评论是正确的:没有嵌入式小部件。但是,您可以通过将鼠标单击绑定到调用 .identify_region、.identify_row 和 .identify_column 方法的函数来使单元格像小部件一样。 (我可能会使用右键单击来避免干扰正常的左键单击功能。)如果您希望某一行响应单击,可以使用标签和 tag_bind。

Tkinter.ttk Treeview reference

Tcl/tk treeview reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 2015-06-11
    • 2011-08-12
    相关资源
    最近更新 更多