从tkinter中的treeview获取数据

时间:2014-05-23 12:34:13

标签: tkinter get treeview

我正在尝试从Treeview中获取数据:

self.tree['show'] = 'headings'
    self.tree['columns'] = ('Pool ID','Time', 'Lat', 'Lon', 'Alt', 'Spd', 'hdop','vdop','pdop', 'Sats Used', 'FixMode')
    self.tree.column('Pool ID', width=90, anchor='center')
    self.tree.heading('Pool ID', text='Pool ID')
    self.tree.column('Time', width=90, anchor='center')
    self.tree.heading('Time', text='Time')
    self.tree.column('Lat', width=90, anchor='center')
    self.tree.heading('Lat', text='Lat')
    self.tree.column('Lon', width=90, anchor='center')
    self.tree.heading('Lon', text='Lon')
    self.tree.column('Alt', width=90, anchor='center')
    self.tree.heading('Alt', text='Alt')
    self.tree.column('Spd', width=90, anchor='center')
    self.tree.heading('Spd', text='Spd')
    self.tree.column('hdop', width=90, anchor='center')
    self.tree.heading('hdop', text='hdop')
    self.tree.column('vdop', width=90, anchor='center')
    self.tree.heading('vdop', text='vdop')
    self.tree.column('pdop', width=90, anchor='center')
    self.tree.heading('pdop', text='pdop')
    self.tree.column('Sats Used', width=90, anchor='center')
    self.tree.heading('Sats Used', text='Sats Used')
    self.tree.column('FixMode', width=90, anchor='center')
    self.tree.heading('FixMode', text='FixMode')

    for i in range(5):

        self.tree.insert('', -1, values=(
                                           i+1,
                                           i+2, 
                                           i+3, 
                                           i+4,
                                           i+5,
                                           i+6,
                                           i+7,
                                           i+8,
                                           i+9,
                                           i+10,
                                           i+11))

我在doc和SO上搜索过,但是我没有找到任何关于它的信息。有人能帮助我吗?

2 个答案:

答案 0 :(得分:2)

好的,我终于找到了如何做,例如显示所有值:

for line in self.tree.get_children():

        for value in self.tree.item(line)['values']:
            print(value)

答案 1 :(得分:0)

使用此代码:

for Parent in self.treeview.get_children():

    print(self.treeview.item(Parent)["text"])

    for child in self.treeview.get_children(Parent):
        data = self.treeview.item(child)["text"]
        print(data)