Afficher détails treeview python
isa.dama
Messages postés
30
Date d'inscription
Statut
Membre
Dernière intervention
-
figro -
figro -
Bonjour
je suis débutant en python et j'ai créer un formulaire avec un treeview.
Mon treeview a été créée à partir d'une requête sql dans une table à plusieurs colonnes (47 colonnes).
Mais dans mon treeview j'ai choisis d'afficher uniquement 3 colonnes.
Mon soucis est que pour obtenir des informations détaillées sur la ligne sélectionnée j'ai besoins d'actualiser plusieurs champs qui sont dans la table sql et non dans les items du treeview.
Il n'y a que les trois champs du treeview qui s'actualisent.
Comment je peux faire pour actualiser les autre champs?
Je vous envoi mon code et une capture d'écran de mon formulaire.
from tkinter import * from tkinter import messagebox, ttk from tkcalendar import * import database import tkinter as tk import os import tempfile import pyodbc from tkinter import ttk class Salarie: def __init__(self, root): self.root = root self.root.title("Gestion de paie") self.root.geometry("1350x705+0+0") '''title = Label(self.root, text="Gestion de Paie", bd=10, relief=RAISED, font=('Algerian', 10), bg='cyan', fg='black') title.pack(side=TOP, fill=Y)''' # Les variables self.matricule= StringVar() self.etablissement = StringVar() self.nom = StringVar() self.prenom = StringVar() self.genre = StringVar() self.mail = StringVar() self.nationalite = StringVar() self.situation = StringVar() self.tel1 = StringVar() self.tel2 = StringVar() self.adresse = StringVar() self.modePaie = StringVar() self.crit1 = StringVar() self.crit2 = StringVar() self.crit3 = StringVar() self.crit4 = StringVar() self.crit5 = StringVar() self.crit6 = StringVar() self.crit7 = StringVar() self.crit8 = StringVar() self.crit9 = StringVar() self.crit10 = StringVar() self.crit11 = StringVar() self.crit12 = StringVar() self.varLibre1 = StringVar() self.varLibre2 = StringVar() self.varLibre3 = StringVar() self.varLibre4 = StringVar() self.varLibre5 = StringVar() self.varLibre6 = StringVar() self.varLibre7 = StringVar() self.varLibre8 = StringVar() self.observation = StringVar() Frame0 = Frame(self.root, bd=2, relief=RIDGE) Frame0.place(x=10, y=5, width=470, height=635) title0 = Label(Frame0, text="Liste salarié", font=("times new roman", 10), bg="lightgray", fg="black") title0.pack(side=TOP, fill=X) detail_frame = Label(Frame0, text="Rechercher par:", font=("times new roman", 12), fg="black") detail_frame.place(x=8, y=30) rech = ttk.Combobox(Frame0, font=("times new roman", 12), state="readonly") rech["values"]=("code", "nom", "prenom") rech.place(x=110, y=30, width=100, height=25) rech.current(0) rech_txt = Entry(Frame0, font=("times new roman", 12), fg="black") rech_txt.place(x=215, y=30, width=150, height=25) btn_recher = Button(Frame0, text="Rechercher", font=("times new roman", 10, "bold"), bg="gray").place(x= 375, y=30) btn_affichtout = Button(Frame0, text="Afficher tout", font=("times new roman", 10, "bold"), bg="gray").place(x=375, y=60) #Affichage result_frame = Frame(Frame0, bd=4, relief=GROOVE, bg="white") result_frame.place(x=5, y=85, width=450, height=150) #scroll_x = Scrollbar(result_frame, orient=HORIZONTAL) scroll_y = Scrollbar(result_frame, orient=VERTICAL) self.tabl_result = ttk.Treeview(result_frame, columns=("matricule", "nom", "prenom"), yscrollcommand=scroll_y.set, height=150) #scroll_x.pack(side=BOTTOM, fill=X) scroll_y.pack(side=RIGHT, fill=Y) self.tabl_result.heading("matricule", text="Matricule", anchor=W) self.tabl_result.heading("nom", text="Nom", anchor=W) self.tabl_result.heading("prenom", text="Prénom(s)", anchor=W) self.tabl_result["show"] = "headings" self.tabl_result.column("matricule", anchor=W, width=80) self.tabl_result.column("nom", anchor=W, width=150) self.tabl_result.column("prenom", anchor=W, width=200) self.tabl_result.pack() self.tabl_result.bind("<ButtonRelease-1>", self.information) self.afficher_result() Frame1 = Frame(self.root, bd=2, relief=RIDGE) Frame1.place(x=480, y=5, width=850, height=635) title2 = Label(Frame1, text="Informations salarié", font=("times new roman", 10), bg="lightgray") title2.pack(side=TOP, fill=X) Framecrit= Frame(self.root, bd=2, relief=RIDGE) Framecrit.place(x=480, y=220, width=415, height=320) critsimple = Label(Framecrit, text="critères simples", font=("times new roman", 9), fg="red") critsimple.pack(side=TOP, fill=X) Framecritx = Frame(self.root, bd=2, relief=RIDGE) Framecritx.place(x=905, y=220, width=415, height=320) critmultiple = Label(Framecritx, text="critères multiples", font=("times new romans", 9), fg="red") critmultiple.pack(side=TOP, fill=X) Frameimage = Frame(self.root, bd=2, relief=RIDGE) Frameimage.place(x=1105, y=65, width=215, height=150) lbl_matricule = Label(Frame1, text="Matricule", font=("times new roman", 12)).place(x=10, y=25) lbl_etabl = Label(Frame1, text="Etablissement", font=("times new roman", 12)).place(x=10, y=55) lbl_nom = Label(Frame1, text="Nom", font=("times new roman", 12)).place(x=10, y=80) lbl_prenom = Label(Frame1, text="Prénom(s)", font=("times new roman", 12)).place(x=10, y=105) lbl_genre = Label(Frame1, text="Genre", font=("times new roman", 12)).place(x=12, y=130) lbl_mail = Label(Frame1, text="E_mail", font=("times new roman", 12)).place(x=12, y=155) lbl_national = Label(Frame1, text="Nationnalité", font=("times new roman", 12)).place(x=10, y=180) lbl_observation = Label(Frame1, text="Observations", font=("times new roman", 12)).place(x=10, y=530) lbl_situation = Label(Frame1, text="Situation familiale", font=("times new roman", 12)).place(x=310, y=55) lbl_naissance = Label(Frame1, text="Date Naissance", font=("times new roman", 12)).place(x=310, y=80) lbl_telephone1 = Label(Frame1, text="Téléphone 1", font=("times new roman", 12)).place(x=310, y=105) lbl_telephone2 = Label(Frame1, text="Téléphone 2", font=("times new roman", 12)).place(x=310, y=130) lbl_adress = Label(Frame1, text="Adresse", font=("times new roman", 12)).place(x=310, y=155) lbl_mode_paie = Label(Frame1, text="Mode paiement", font=("times new roman", 12)).place(x=310, y=180) lbl_varlibre1 = Label(Frame1, text="VarLibre1", font=("times new roman", 12)).place(x=355, y=530) lbl_varlibre2 = Label(Frame1, text="VarLibre2", font=("times new roman", 12)).place(x=355, y=555) lbl_varlibre3 = Label(Frame1, text="VarLibre3", font=("times new roman", 12)).place(x=355, y=580) lbl_varlibre4 = Label(Frame1, text="VarLibre4", font=("times new roman", 12)).place(x=355, y=600) lbl_varlibre5 = Label(Frame1, text="VarLibre5", font=("times new roman", 12)).place(x=600, y=530) lbl_varlibre6 = Label(Frame1, text="VarLibre6", font=("times new roman", 12)).place(x=600, y=555) lbl_varlibre7 = Label(Frame1, text="VarLibre7", font=("times new roman", 12)).place(x=600, y=580) lbl_varlibre8 = Label(Frame1, text="VarLibre8", font=("times new roman", 12)).place(x=600, y=600) lbl_photo = Label(Frame1, text="Photo d'identité", font=("times new roman", 12)).place(x=625, y=25) lbl_crit1 = Label(Framecrit, text="Critère 1", font=("times new roman", 12)).place(x=10, y=17) lbl_crit2 = Label(Framecrit, text="Critère 2", font=("times new roman", 12)).place(x=10, y=42) lbl_crit3 = Label(Framecrit, text="Critère 3", font=("times new roman", 12)).place(x=10, y=67) lbl_crit4 = Label(Framecrit, text="Critère 4", font=("times new roman", 12)).place(x=10, y=92) lbl_crit5 = Label(Framecrit, text="Critère 5", font=("times new roman", 12)).place(x=10, y=117) lbl_crit6 = Label(Framecrit, text="Critère 6", font=("times new roman", 12)).place(x=10, y=142) lbl_crit7 = Label(Framecrit, text="Critère 7", font=("times new roman", 12)).place(x=10, y=166) lbl_crit8 = Label(Framecrit, text="Critère 8", font=("times new roman", 12)).place(x=10, y=192) lbl_crit9 = Label(Framecrit, text="Critère 9", font=("times new roman", 12)).place(x=10, y=217) lbl_crit10 = Label(Framecrit, text="Critère 10", font=("times new roman", 12)).place(x=10, y=242) lbl_crit11 = Label(Framecrit, text="Critère 11", font=("times new roman", 12)).place(x=10, y=267) lbl_crit12 = Label(Framecrit, text="Critère 12", font=("times new roman", 12)).place(x=10, y=292) self.matricule = Entry(Frame1, textvariable=self.matricule, font=('times new roman', 10), bg="lightyellow") self.matricule.place(x=115, y=25, width=100) self.etablissement = ttk.Combobox(Frame1, textvariable=self.etablissement, font=('times new roman', 10), state="readonly") self.etablissement["values"] = (1,2,3) self.etablissement.place(x=115, y=55, width=175) self.etablissement.current(0) self.nom = Entry(Frame1, textvariable=self.nom, font=('times new roman', 10), bg="lightyellow") self.nom.place(x=115, y=80, width=175) self.prenom = Entry(Frame1, textvariable=self.prenom, font=('times new roman', 10), bg="lightyellow") self.prenom.place(x=115, y=105, width=175) self.genre = ttk.Combobox(Frame1, textvariable=self.genre, font=('time new roman', 10), state="readonly") self.genre["values"] = (1,2) self.genre.place(x=115, y=130, width=175) self.genre.current(0) self.mail = Entry(Frame1, textvariable=self.mail, font=('E_mail', 10), bg="lightyellow") self.mail.place(x=115, y=155, width=175) self.nationalite = ttk.Combobox(Frame1, textvariable=self.nationalite, font=('time new roman', 10), state="readonly") self.nationalite["values"] = (1,2,3,4) self.nationalite.place(x=115, y=180, width=175) self.nationalite.current(0) self.observation = Text(Frame1, font=("time new roman", 10), bg="lightyellow") self.observation.place(x=115, y=540, width=230, height=90) self.situation = ttk.Combobox(Frame1, textvariable=self.situation, font=('time new roman', 10), state="readonly") self.situation["values"] = (1,2,3,4) self.situation.place(x=440, y=55, width=175) self.situation.current(0) self.ecri_date = DateEntry(Frame1, font=("time new roman", 10), bg="lightyellow", state="readonly", locale='fr_FR', date_pattern = 'dd/mm/yyyy') self.ecri_date.place(x=440, y=80, width=175) self.tel1 = Entry(Frame1,textvariable=self.tel1, font=("time new roman", 10), bg="lightyellow") self.tel1.place(x=440, y=105, width=175) self.tel2 = Entry(Frame1, textvariable=self.tel2, font=("time new roman", 10), bg="lightyellow") self.tel2.place(x=440, y=130, width=175) self.adresse = Entry(Frame1, textvariable=self.adresse, font=("time new roman", 10), bg="lightyellow") self.adresse.place(x=440, y=155, width=175) self.modePaie = ttk.Combobox(Frame1, textvariable=self.modePaie, font=('time new roman', 10), state="readonly") self.modePaie["values"] = (1,2,3,4,5) self.modePaie.place(x=440, y=180, width=175) self.modePaie.current(0) self.crit1 = ttk.Combobox(Framecrit, textvariable=self.crit1, font=('time new roman', 10), state="readonly") self.crit1["values"] = (1,2,3,4,5) self.crit1.place(x=170, y=20, width=240) self.crit1.current(0) self.crit2 = ttk.Combobox(Framecrit, textvariable=self.crit2, font=('time new roman', 10), state="readonly") self.crit2["values"] = (1,2,3,4,5) self.crit2.place(x=170, y=45, width=240) self.crit2.current(0) self.crit3 = ttk.Combobox(Framecrit, textvariable=self.crit3, font=('time new roman', 10), state="readonly") self.crit3["values"] = (1,2,3,4,5) self.crit3.place(x=170, y=70, width=240) self.crit3.current(0) self.crit4 = ttk.Combobox(Framecrit, textvariable=self.crit4, font=('time new roman', 10), state="readonly") self.crit4["values"] = (1,2,3,4,5) self.crit4.place(x=170, y=95, width=240) self.crit4.current(0) self.crit5 = ttk.Combobox(Framecrit, textvariable=self.crit5, font=('time new roman', 10), state="readonly") self.crit5["values"] = (1,2,3,4,5) self.crit5.place(x=170, y=120, width=240) self.crit5.current(0) self.crit6 = ttk.Combobox(Framecrit, textvariable=self.crit6, font=('time new roman', 10), state="readonly") self.crit6["values"] = (1,2,3,4,5) self.crit6.place(x=170, y=145, width=240) self.crit6.current(0) self.crit7 = ttk.Combobox(Framecrit, textvariable=self.crit7, font=('time new roman', 10), state="readonly") self.crit7["values"] = (1,2,3,4,5) self.crit7.place(x=170, y=170, width=240) self.crit7.current(0) self.crit8 = ttk.Combobox(Framecrit, textvariable=self.crit8, font=('time new roman', 10), state="readonly") self.crit8["values"] = (1,2,3,4,5) self.crit8.place(x=170, y=195, width=240) self.crit8.current(0) self.crit9 = ttk.Combobox(Framecrit, textvariable=self.crit9, font=('time new roman', 10), state="readonly") self.crit9["values"] = (1,2,3,4,5) self.crit9.place(x=170, y=220, width=240) self.crit9.current(0) self.crit10 = ttk.Combobox(Framecrit, textvariable=self.crit10, font=('time new roman', 10), state="readonly") self.crit10["values"] = (1,2,3,4,5) self.crit10.place(x=170, y=245, width=240) self.crit10.current(0) self.crit11 = ttk.Combobox(Framecrit, textvariable=self.crit11, font=('time new roman', 10), state="readonly") self.crit11["values"] = (1,2,3,4,5) self.crit11.place(x=170, y=270, width=240) self.crit11.current(0) self.crit12 = ttk.Combobox(Framecrit, textvariable=self.crit12, font=('time new roman', 10), state="readonly") self.crit12["values"] = (1,2,3,4,5) self.crit12.place(x=170, y=295, width=240) self.crit12.current(0) self.varLibre1 = Entry(Frame1, textvariable=self.varLibre1, font=('times new roman', 10), bg="lightyellow") self.varLibre1.place(x=445, y=535, width=140) self.varLibre2 = Entry(Frame1, textvariable=self.varLibre2, font=('times new roman', 10), bg="lightyellow") self.varLibre2.place(x=445, y=562, width=140) self.varLibre3 = Entry(Frame1, textvariable=self.varLibre3, font=('times new roman', 10), bg="lightyellow") self.varLibre3.place(x=445, y=585, width=140) self.varLibre4 = Entry(Frame1, textvariable=self.varLibre4, font=('times new roman', 10), bg="lightyellow") self.varLibre4.place(x=445, y=608, width=140) self.varLibre5 = Entry(Frame1, textvariable=self.varLibre5, font=('times new roman', 10), bg="lightyellow") self.varLibre5.place(x=700, y=535, width=140) self.varLibre6 = Entry(Frame1, textvariable=self.varLibre6, font=('times new roman', 10), bg="lightyellow") self.varLibre6.place(x=700, y=562, width=140) self.varLibre7 = Entry(Frame1, textvariable=self.varLibre7, font=('times new roman', 10), bg="lightyellow") self.varLibre7.place(x=700, y=585, width=140) self.varLibre8 = Entry(Frame1, textvariable=self.varLibre8, font=('times new roman', 10), bg="lightyellow") self.varLibre8.place(x=700, y=608, width=140) btn_ajout = Button( text="Ajouter", command=self.ajout_salarie, font=("times new roman", 10, "bold"),relief=GROOVE, bg="green").place(x=11, y=660) btn_modif = Button(text="Modifier", font=("times new roman", 10, "bold"),relief=GROOVE, bg="yellow").place(x=75, y=660) btn_suppr = Button(text="Supprimer", font=("times new roman", 10, "bold"),relief=GROOVE, bg="red").place(x=145, y=660) btn_reini = Button(text="Réinitialiser", font=("times new roman", 10, "bold"),relief=GROOVE, bg="blue").place(x=225, y=660) def reini(self): self.matricule.delete(0, END) self.etablissement.delete(0, END) self.nom.delete(0, END) self.prenom.delete(0, END) self.genre.delete(0, END) self.mail.delete(0, END) self.nationalite.delete(0, END) self.situation.delete(0, END) self.ecri_date.set_date("01/01/1900") self.tel1.delete(0, END) self.tel2.delete(0, END) self.adresse.delete(0, END) self.modePaie.delete(0, END) self.crit1.delete(0, END) self.crit2.delete(0, END) self.crit3.delete(0, END) self.crit4.delete(0, END) self.crit5.delete(0, END) self.crit6.delete(0, END) self.crit7.delete(0, END) self.crit8.delete(0, END) self.crit9.delete(0, END) self.crit10.delete(0, END) self.crit11.delete(0, END) self.crit12.delete(0, END) self.varLibre1.delete(0, END) self.varLibre2.delete(0, END) self.varLibre3.delete(0, END) self.varLibre4.delete(0, END) self.varLibre5.delete(0, END) self.varLibre6.delete(0, END) self.varLibre7.delete(0, END) self.varLibre8.delete(0, END) self.observation.delete("1.0", "end") def ajout_salarie(self): if self.matricule.get() == "" : messagebox.showerror("Attention:", "Vous devez renseigner le matricule", parent=self.root) elif self.nom.get() == "" : messagebox.showerror("Attention:", "Vous devez rensigner le nom", parent=self.root) elif self.prenom.get() == "": messagebox.showerror("Attention:", "Vous devez rensigner le Prénom(s)", parent=self.root) else: try: cursor = database.conn.cursor() cursor.execute("select* from salarie where matricule=?", self.ecri_date.get()) row = cursor.fetchone() if row != None: messagebox.showerror("Erreur:", "Cette données existe déjà", parent=self.root) else: cursor.execute( "INSERT INTO salarie(Matricule,Etabl,Nom,Prenoms,Sexe,PaysNationalite,Email,SituationFamiliale,DateNaissance," "Telephone1,Telephone2, Adresse,ModePaiement,Crit1,Crit2,Crit3,Crit4,Crit5,Crit6,Crit7,Crit8" ",Crit9,Crit10,Crit11,Crit12,VarLibre1,VarLibre2,VarLibre3,VarLibre4,VarLibre5,VarLibre6,VarLibre7,VarLibre8,ObSalarie) " "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (self.matricule.get(), self.etablissement.get(), self.nom.get(), self.prenom.get(), self.genre.get(), self.nationalite.get(), self.mail.get(), self.situation.get(), self.ecri_date.get(), self.tel1.get(), self.tel2.get(), self.adresse.get(), self.modePaie.get(), self.crit1.get(), self.crit2.get(), self.crit3.get(), self.crit4.get(), self.crit5.get(), self.crit6.get(), self.crit7.get(), self.crit8.get(), self.crit9.get(), self.crit10.get(), self.crit11.get(), self.crit12.get(), self.varLibre1.get(), self.varLibre2.get(), self.varLibre3.get(), self.varLibre4.get(), self.varLibre5.get(), self.varLibre6.get(), self.varLibre7.get(), self.varLibre8.get(), self.observation.get("1.0", END))) database.conn.commit() self.afficher_result() #database.conn.close() messagebox.showinfo("Salarié enregistré avec succès") self.reini() except Exception as es: messagebox.showerror("Erreur:", f" {str(es)}", parent=self.root) def afficher_result(self): cursor = database.conn.cursor() cursor.execute("select * from salarie") rows = cursor.fetchall() if len(rows) != 0: self.tabl_result.delete(* self.tabl_result.get_children()) for row in rows: self.tabl_result.insert("", END, values=(row[0], row[2], row[3] )) database.conn.commit() #database.conn.close() def information(self, ev): cursor_row = self.tabl_result.focus() contents = self.tabl_result.item(cursor_row) row = contents["values"] self.matricule.delete(0, END), self.matricule.insert(END, row[0]), self.etablissement.set(row[1]), self.nom.delete(0, END), self.nom.insert(END, row[2]), self.prenom.delete(0, END), self.prenom.insert(0, row[3]), self.genre.set(row[4]), self.nationalite.set(row[5]), self.mail.delete(0, END) self.mail.insert(END, row[6]), self.situation.set(row[7]), self.ecri_date.set(row[8]), self.tel1.delete(0, END) self.tel1.insert(END, row[11]), self.tel2.delete(0, END) self.tel2.insert(END, row[12]), self.adresse.delete(0, END) self.adresse.insert(END, row[13]), self.modePaie.set(row[14]), self.crit1.set(row[15]), self.crit2.set(row[16]), self.crit3.set(row[17]), self.crit4.set(row[18]), self.crit5.set(row[19]), self.crit6.set(row[20]), self.crit7.set(row[21]), self.crit8.set(row[22]), self.crit9.set(row[23]), self.crit10.set(row[24]), self.crit11.set(row[25]), self.crit12.set(row[26]), self.critx1.set(row[27]), self.critx2.set(row[28]), self.critx3.set(row[29]), self.critx4.set(row[30]), self.critx5.set(row[31]), self.critx6.set(row[32]), self.critx7.set(row[33]), self.critx8.set(row[34]), self.critx9.set(row[35]), self.critx10.set(row[36]), self.critx11.set(row[37]), self.critx12.set(row[38]), self.varLibre1.delete("1.0", "end"), self.varLibre1.insert(END, row[39]), self.varLibre2.delete("1.0", "end"), self.varLibre2.insert(END, row[40]), self.varLibre3.delete("1.0", "end"), self.varLibre3.insert(END, row[41]), self.varLibre4.delete("1.0", "end"), self.varLibre4.insert(END, row[42]), self.varLibre5.delete("1.0", "end"), self.varLibre5.insert(END, row[43]), self.varLibre6.delete("1.0", "end"), self. varLibre6.insert(END, row[44]), self.varLibre7.delete("1.0", "end"), self.varLibre7.insert(END, row[45]), self.varLibre8.delete("1.0", "end"), self.varLibre8.insert(END, row[46]), self.observation.delete("1.0", "end"), self.observation.insert(END, row[47]) root = Tk() obj = Salarie(root) root.mainloop()
A voir également:
- Afficher détails treeview python
- Citizen code python avis - Accueil - Outils
- Afficher appdata - Guide
- Afficher taille dossier windows - Guide
- Windows 11 afficher d'autres options - Guide
- Afficher mot de passe wifi android - Guide