Reputation: 432
I have created tree view in tkinter and the column code is here
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()
For retrieving the selected row I used the below code
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'])
while printing the contents[values] the first row #0
which I named as S.No is not printed. Is there any way of retrieving those values from #0
There are eight columns but only 7 values are printed. The first row is not printed. Please help me!
Upvotes: 1
Views: 956
Reputation: 8062
Column #0 is the one by default and normally filled by the option text. So I guess #0 is not a value.
try adding print(self.contents['text'])
before this line print(self.contents['values'])
and see.
Upvotes: 1