我在tkinter中创建了树视图,列代码在这里
self.treeview = ttk.Treeview(self.treeviewFrame)
self.treeview['columns'] = ('1','2','3','4','5','6','7')
self.treeview.column('#0',width=50,minwidth=25)
self.treeview.column('1',width=50,minwidth=25,anchor=W)
self.treeview.column('2',width=50,minwidth=25,anchor=W)
self.treeview.column('3',width=50,minwidth=25,anchor=W)
self.treeview.column('4',width=50,minwidth=25,anchor=W)
self.treeview.column('5',width=50,minwidth=25,anchor=W)
self.treeview.column('6',width=50,minwidth=25,anchor=W)
self.treeview.column('7',width=50,minwidth=25,anchor=W)
self.treeview.bind('<ButtonRelease-1>',self.selectedRow)
self.treeview.pack(fill=BOTH,expand=1)
self.treeViewData()
为了检索选定的行,我使用了以下代码
self.treeview.bind('<ButtonRelease-1>',self.selectedRow)
def selectedRow(self,a):
self.curItem = self.treeview.focus()
self.contents = self.treeview.item(self.curItem)
print(self.contents['values'])
在打印内容[值]时,#0
不打印我命名为S.No的第一行。有什么办法可以从中检索这些值#0
一共有八列,但只打印了7个值。第一行不打印。请帮我!
列#0是默认列,通常由选项文本填充。所以我猜#0不是值。
尝试print(self.contents['text'])
在此行之前添加print(self.contents['values'])
并查看。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句