Utilisation d’une TreeView avec Rest

Utilisation :

from tkinter import *                            
from tkinter.ttk import *    
import requests

def ajouterData():
    data = {'data':'{"name":"'+produit_name.get()+'", "type":"'+produit_type.get()+'","price":'+produit_price.get()+'}'}
    result = requests.post(url_srv,data=data)
    tableau.insert('', 'end', iid=int(result.text),
    values=(result.text, produit_name.get(),
    produit_type.get(),produit_price.get()))
    #print(result.text) #debug
    return

def modifierData():
    tableau.item(curent_item, values=(
    tableau.item(curent_item)['values'][0], produit_name.get(),
    produit_type.get(),produit_price.get()))
    data = {'data':'{"name":"'+produit_name.get()+'", "type":"'+produit_type.get()+'","price":'+produit_price.get()+'}'}
    result = requests.put(url_srv+str(tableau.item(curent_item)['values'][0]),data=data)
    #print(result.text) #debug
    return 

def supprimerData():
    if(tableau.exists(curent_item)):
        result = requests.delete(url_srv+str(tableau.item(curent_item)['values'][0]))
        # print(result.text) #debug
        tableau.delete(curent_item)
    return

def selectData(a):
    global curent_item
    curent_item = tableau.focus()
    produit_id.config(text = (tableau.item(tableau.focus())['values'][0]))
    produit_name.delete('0', 'end')
    produit_name.insert('0', tableau.item(tableau.focus())['values'][1])    
    produit_type.delete('0', 'end')
    produit_type.insert('0', tableau.item(tableau.focus())['values'][2])    
    produit_price.delete('0', 'end')    
    produit_price.insert('0', tableau.item(tableau.focus())['values'][3])
    return

curent_item=-1
cpt_id=5            
url_srv=    "https://<URL_SERVEUR>/gr0/product/"
# fenêtre principale                            
fenetre = Tk()                        
fenetre.title('Produits')        
fenetre.grid_rowconfigure(0, weight=1)
fenetre.grid_columnconfigure(0, weight=1)
fenetre.grid_columnconfigure(1, weight=1)
fenetre.grid_columnconfigure(2, weight=1)    
fenetre.grid_columnconfigure(3, weight=1)                
                                    
# libellé                                    
libelle = Label(fenetre, text = 'Produits')    
libelle.grid(row=0, column=0, columnspan=4, pady=5)                            
                                    
#tableau                                
tableau = Treeview(fenetre, columns=('id', 'name', 'type', 'price'))        
tableau.heading('id', text='id')                        
tableau.heading('name', text='name')                    
tableau.heading('type', text='type')                    
tableau.heading('price', text='price')                    
# sans ceci, il y avait une colonne vide à gauche qui a pour rôle         
# d'afficher le paramètre "text" qui peut être spécifié lors du insert    
tableau['show'] = 'headings'         
tableau.grid(row=1, column=0, columnspan=4, padx=5, pady=5)                        
                                
response = requests.get(url_srv) #GET request to server
data_got = response.json() #Store into var json content
for i in data_got:
    tableau.insert('', 'end', iid=i['id'], values=(i['id'], i['name'], i['type'], i['price']))              
tableau.bind('<ButtonRelease-1>', selectData)
         
produit_id = Label(fenetre, text="Id")            
produit_name = Entry(fenetre)        
produit_type = Entry(fenetre)        
produit_price = Entry(fenetre)

produit_id.grid(row=2, column=0, padx=5, pady=5)
produit_name.grid(row=2, column=1, padx=5, pady=5)
produit_type.grid(row=2, column=2, padx=5, pady=5)
produit_price.grid(row=2, column=3, padx=5, pady=5)
        
bouton_ajouter = Button(fenetre, text="Ajouter", command=ajouterData)
bouton_ajouter.grid(row=3, column=0, padx=5, pady=5)    

bouton_modifier = Button(fenetre, text="Modifier", command=modifierData)
bouton_modifier.grid(row=3, column=1, padx=5, pady=5)    

bouton_supprimer = Button(fenetre, text="Supprimer", command=supprimerData)
bouton_supprimer.grid(row=3, column=2, padx=5, pady=5)    

# bouton pour quitter le programme                    
bouton_terminer = Button(fenetre, text = 'Quitter', command = fenetre.destroy)
bouton_terminer.grid(row=3, column=3, padx=5, pady=5)    
fenetre.mainloop()