Inserir os valores das colunas do ttk.Treeview para o Entry.

693 views
Skip to first unread message

Augusto Le

unread,
Aug 8, 2018, 3:19:35 PM8/8/18
to Python Brasil
Qual o comando para capturar os valores  das colunas do ttk.Treeview  e inserir no Entry? 
Ao clicar numa linha do treeview preciso carregar os Entry com os valores correspondentes de cada coluna:    NOME, CARGO, ENDEREÇO, TELEFONE

Consegui apenas capturar o valor do "TEXT'  ou seja coluna ZERO


TRECHO DO CÓDIGO

        self.tree = ttk.Treeview( self.parent, columns=('Nome','Cargo', 'Endereco','Telefone'),show='headings')

        # Barras de rolagem
        ysb = ttk.Scrollbar(orient=VERTICAL, command=self.tree.yview)
        xsb = ttk.Scrollbar(orient=HORIZONTAL, command=self.tree.xview)
        self.tree['yscroll'] = ysb.set
        self.tree['xscroll'] = xsb.set
        ysb.grid(row=6, column=1, sticky='nse')
        xsb.grid(row=7, columnspan=4, sticky='nswe')


        self.tree.heading('#0', text='CODIGO')
        self.tree.heading('#1', text='NOME')        
        self.tree.heading('#2', text='CARGO')
        self.tree.heading('#3', text='ENDEREÇO')
        self.tree.heading('#4', text='TELEFONE')        
        self.tree.column('#0', stretch=YES, minwidth=100, width=180, anchor="se")
        self.tree.column('#1', stretch=YES, minwidth=100, width=210, anchor="se")
        self.tree.column('#2', stretch=YES, minwidth=100, width=150, anchor="se")
        self.tree.column('#3', stretch=YES, minwidth=100, width=480, anchor="se")        
        self.tree.column('#4', stretch=YES, minwidth=100, width=250, anchor="se")
        self.tree.bind("<Double-1>", self.OnDoubleClick)

        self.tree.grid(row=6, columnspan=4, sticky='nsw')  
        self.treeview = self.tree

    # Initialize the counter
        self.i = 0

 
    def insert_data(self):
        self.treeview.insert('', 'end', text="N. "+str(self.i), values= (self.nome_entry.get(), self.cargo_entry.get(), self.endereco_entry.get(), self.telefone_entry.get()) ) 
        self.i = self.i + 1


    def OnDoubleClick(self, event):

        item = self.tree.identify("item", event.x, event.y)
        print ( self.tree.item(item)["text"] )


 



Reply all
Reply to author
Forward
0 new messages