3 回答
TA贡献1836条经验 获得超5个赞
代码如下,请将#替换为空格:
import tkinter
from tkinter import ttk
def popup(event):
####print(tree.selection())
####string.set(tree.selection()[0])
####string.set(tree.focus())
win=tkinter.Tk()
tree=ttk.Treeview(win)
global string
string = tkinter.StringVar()
label=tkinter.Label(win, text="项目", textvariable=string)
myid=tree.insert("",0,"浙江",text="浙江",values=("1"))
myidx1=tree.insert(myid,0,"杭州",text="杭州",values=("2"))
myidx2=tree.insert(myid,1,"宁波",text="宁波",values=("3"))
myidy=tree.insert("",1,"山西",text="山西",values=("4"))
myidy1=tree.insert(myidy,0,"太原",text="太原",values=("5"))
myidy1=tree.insert(myidy,2,"大同",text="大同",values=("6"))
tree.bind("<ButtonRelease-1>", popup)
tree.pack()
label.pack()
win.mainloop()
TA贡献1895条经验 获得超3个赞
定义这样的函数去专门取tree上的值
def selectItem(a):
curItem = tree.focus()
print tree.item(curItem)
它返回一个字典类型的集合,你只要遍历字典就可以把你需要的值取出来。
TA贡献1890条经验 获得超9个赞
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { Response.Write(TreeView1.SelectedNode.Value); } protected void Button1_Click(object sender, EventArgs e) { if(TreeView1.SelectedNode!=null) Response.Write("获取当前节点的value:" + TreeView1.SelectedNode.Value); }
- 3 回答
- 0 关注
- 1300 浏览
添加回答
举报