一只甜甜圈
代码如下,请将#替换为空格:import tkinterfrom tkinter import ttkdef popup(event):####print(tree.selection())####string.set(tree.selection()[0])####string.set(tree.focus())win=tkinter.Tk()tree=ttk.Treeview(win)global stringstring = 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()