如何在树视图中添加按钮? [英] How add button in treeview?

查看:92
本文介绍了如何在树视图中添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote a program in python 3.6.4 using tkinter library

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()

我想在树视图上添加按钮,但我不知道如何.

I want add button on treeview, and I do not how.

推荐答案

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

The comment by @kogito is correct: no embedded widgets. However, you can make a cell act like a widget by binding mouse clicks to a function that calls the .identify_region, .identify_row, and .identify_column methods. (I might use right clicks to avoid interfering with normal left click functions.) If you want certain row to respond to clicks, one can use tags and tag_bind.

Tkinter.ttk 树视图参考

Tcl/tk 树视图参考

这篇关于如何在树视图中添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆