我已经设置了一个树视图来显示来自我的sqlite数据库的数据。我能够用查询填充第一列,现在我需要用其他查询填充其他列。
# Top Container
top_frame = ttk.Frame()
top_frame.grid(column=0, row=0)
# create a treeview with dual scrollbars
list_header = ['First', 'Second', 'Third']
self.tree = ttk.Treeview(columns=list_header, show="headings")
vsb = ttk.Scrollbar(orient="vertical",
command=self.tree.yview)
hsb = ttk.Scrollbar(orient="horizontal",
command=self.tree.xview)
self.tree.configure(yscrollcommand=vsb.set,
xscrollcommand=hsb.set)
self.tree.grid(column=0, row=0, sticky=(N, S, E, W), in_=top_frame)
vsb.grid(column=1, row=0, sticky=(N, S), in_=top_frame)
hsb.grid(column=0, row=1, sticky=(E, W), in_=top_frame)
# Display the headers
for col in list_header:
self.tree.heading(col, text=col.title(), command=lambda c=col: sortby(self.tree, c, 0))
# adjust the column's width to the header string
self.tree.column(col)
# Display the data
query = ProjectNumber.select()
for item in query:
self.tree.insert('', 'end', values=item.project_num)
how can i access the next column and fill it with a separate query?
答案 0 :(得分:0)
据我了解,您可以在下面看到您想做的工作示例。
该示例是以oo方法编写的。
启动脚本后,单击“加载”按钮,您将看到树视图填充
模拟记录集的数据,元组列表。尝试点击
的项目后treeview,看看会发生什么。我已经添加了单击事件和双击事件的回调。
数据代表意大利面食。
{{1}}