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
| try:
from Tkinter import *
import ttk
except:
from tkinter import *
from tkinter import ttk
ROWS = [('Dupont', 'Jean', 12356), ('Doe', 'John', 6789), ('Chaplin', 'Charlie', 67891)]
fenetre = Tk()
def on_click(event):
seltxt = tv.set(tv.selection(), 'col1') or 'None'
labsel.configure(text=seltxt)
selfocus = tv.set(tv.focus(), 'col1') or 'None'
labfocus.configure(text=selfocus)
frm = Frame(fenetre)
labseltitle = Label(frm, text='selection')
labseltitle.grid(row=0, column=0, sticky=E+W, padx=5)
labsel = Label(frm, text='None')
labsel.grid(row=1, column=0, sticky=E+W, padx=5)
labfocustitle = Label(frm, text='focus')
labfocustitle.grid(row=0, column=1, sticky=E+W, padx=5)
labfocus = Label(frm, text='None')
labfocus.grid(row=1, column=1, sticky=E+W, padx=5)
frm.pack(fill=Y)
# la creation de la TreeView
tv = ttk.Treeview(fenetre, show='headings', height=3, selectmode='browse')
tv["columns"]=("col1", "col2", "col3")
tv.column("col1", width=80, anchor="center")
tv.column("col2", width=80, anchor="center")
tv.column("col3", width=110, anchor="center")
tv.heading("col1", text="Nom")
tv.heading("col2", text="Prenom")
tv.heading("col3", text="Phone number")
tv.pack()
for row in ROWS:
tv.insert('','end', text=row[0], values=row, tags=('mb3_click',))
tv.bind("<Button-1>", on_click)
#tv.bind("<Button-3>", on_click)
tv.tag_bind('mb3_click', '<3>', on_click)
Button(fenetre, text='Test', command=lambda: on_click(None)).pack()
fenetre.mainloop() |
Partager