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
|
from tkinter import *
from tkinter import ttk
Debug = 1
def SimpleClick_Treeview(event):
if Debug ==1 : print('SimpleClick_Treeview')
# Acquisition de l'indicatif selectionné par le click de souris
item = tree.item(tree.selection())['values']
if Debug ==1 : print ("Element selectionne : ",item)
Nom=item[1]
Centre = Label (root , text = Nom , bg="black" , fg="white" , font="broadway 18 bold " )
Centre.place(x=10,y=10, width=400)
def DoubleClick_Treeview(event):
if Debug ==1 : print('DoubleClick_Treeview')
# Acquisition de l'indicatif selectionné par le click de souris
item = tree.item(tree.selection())['values']
if Debug ==1 : print ("Element selectionne : ",item)
Nom=item[1]
Centre = Label (root , text = Nom , bg="black" , fg="white" , font="broadway 18 bold " )
Centre.place(x=10,y=10, width=400)
Nom=''
root=Tk()
root.geometry( "500x200" )
Centre = Label (root , text = Nom , bg="black" , fg="white" , font="broadway 18 bold " )
Centre.place(x=10,y=10, width=400)
# === Création de l " objet Treeview ===
tree=ttk.Treeview( root , columns = (1 ,2 ,3 ,4) , height = 5 ,show = "headings" )
tree.place(x=50,y=50, width=400)
tree.column(1 , width = 20)
tree.column(2 , width = 70)
tree.column(3 , width = 150)
tree.column(4 ,width=50)
# === Création de l " entête ===
tree.heading(1 , text="ID" )
tree.heading(2 , text="Nom" )
tree.heading(3 , text="Email" )
tree.heading(4 , text="Age" )
# === Insertion des données ===
tree.insert( "" , "end" , values = (1 , "Albert " , "albert@gmail.com" ,27) )
tree.insert( "" , "end" , values = (1 , "Majid" , "majid@gmail.com" ,33) )
tree.insert( "" , "end" , values = (1 , " Natalie " , "natalie@gmail.com" ,21) )
tree.bind("<Double-1>", DoubleClick_Treeview)
tree.bind("<Button-1>", SimpleClick_Treeview)
root .mainloop () |
Partager