我正在尝试从树状视图生成的数据结构中获取特定值。
这是正在定义的树视图。
ScoutCalenderView= ttk.Treeview(ScoutCalendar)
ScoutCalenderView["columns"] = ("eventname","startdate","enddate","starttime","endtime","cost","limits")
ScoutCalenderView.grid(row=1,column=1)
ScoutCalenderView.heading("#0", text="",anchor="w")
ScoutCalenderView.column("#0",anchor="center",width=5,stretch=tk.NO)
ScoutCalenderView.heading("eventname", text="Event Name",anchor="w")
ScoutCalenderView.column("eventname",anchor="center",width=80)
ScoutCalenderView.heading("startdate", text="Start Date",anchor="w")
ScoutCalenderView.column("startdate",anchor="center",width=70)
ScoutCalenderView.heading("enddate", text="End Date",anchor="w")
ScoutCalenderView.column("enddate",anchor="center",width=70)
ScoutCalenderView.heading("starttime", text="Start Time",anchor="w")
ScoutCalenderView.column("starttime",anchor="center",width=70)
ScoutCalenderView.heading("endtime", text="End Time",anchor="w")
ScoutCalenderView.column("endtime",anchor="center",width=70)
ScoutCalenderView.heading("cost", text="Cost",anchor="w")
ScoutCalenderView.column("cost",anchor="center",width=70)
ScoutCalenderView.heading("limits", text="Limit",anchor="w")
ScoutCalenderView.column("limits",anchor="center",width=70)
ScoutCalenderView.bind('<ButtonRelease-1>', selectItem)
ScoutCalenderView.grid(row=3,column=1,columnspan=5)
这是释放按钮时调用的函数。
def selectItem(a):
curItem = ScoutCalenderView.focus()
print(ScoutCalenderView.item(curItem))
行print(ScoutCalenderView.item(curItem))产生,例如:
{'text': '', 'image': '', 'values': ['jhgfds', '16/11/2018', '16/11/2018', '14:35', '14:35', '£0.0', 0], 'open': 0, 'tags': ''}
如您所见,字典的value部分中只有数据。我希望能够获得列表中的值。
答案 0 :(得分:0)
您可以简单地从字典中提取“值”。它会给您一个列表:
inter_var=ScoutCalenderView.item(curItem)
list_values=inter_var['values']
如果打印list_values
,在这种情况下,您将获得:
['jhgfds', '16/11/2018', '16/11/2018', '14:35', '14:35', '£0.0', 0]