1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
from tkinter import *
data = [{
"id": "010101",
"nom": "Dupont1",
"prenom": "Martin1",
"adresse": "16 rue de rivoli",
"tel": "06.00.00.00.00",
"mail": "truc1@gmail.com",
"contact": "Robert1",
"nb_fac": "16",
"nb_devis": "32",
"nb_avoirs": "64"
},
{
"id": "020202",
"nom": "Dupont2",
"prenom": "Martin2",
"adresse": "16 rue de rivoli",
"tel": "06.00.00.00.00",
"mail": "truc2@gmail.com",
"contact": "Robert2",
"nb_fac": "16",
"nb_devis": "32",
"nb_avoirs": "64"
},
{
"id": "030303",
"nom": "Dupont3",
"prenom": "Martin3",
"adresse": "16 rue de rivoli",
"tel": "06.00.00.00.00",
"mail": "truc3@gmail.com",
"contact": "Robert3",
"nb_fac": "16",
"nb_devis": "32",
"nb_avoirs": "64"
},
{
"id": "040404",
"nom": "Dupont4",
"prenom": "Martin4",
"adresse": "16 rue de rivoli",
"tel": "06.00.00.00.00",
"mail": "truc4@gmail.com",
"contact": "Robert4",
"nb_fac": "16",
"nb_devis": "32",
"nb_avoirs": "64"
}
]
entete = ["Id", "Nom", "Prénom", "Adresse", "Téléphone", "Mail", "Contact", "Nb Factures", "Nb Devis", "Nb Avoirs"]
champ = ["id", "nom", "prenom", "adresse", "tel", "mail", "contact", "nb_fac", "nb_devis", "nb_avoirs"]
######################################################################
def do_click(label_clients):
print(label_clients['textvariable'])
def on_click(e):
if isinstance(e.widget, Label):
do_click(e.widget)
root = Tk()
frame = Frame(root, name='labels')
frame.pack()
for i in range(0, len(entete)):
for j in range(2, len(data) + 2):
color = ['grey85', 'white'][j % 2]
label_clients = Label(frame, text="%s" % (data[j - 2][champ[i]][:50]), textvariable=data[j - 2][champ[0]],
bg=color, bd=1, relief=RAISED, width=20, anchor='w', font="arial, 9")
label_clients.grid(row=j, column=i, ipadx=3, ipady=3)
root.bind('<1>', on_click)
mainloop() |