Affichage des articles dont le libellé est Python Tkinter Populating Treeview. Afficher tous les articles
Affichage des articles dont le libellé est Python Tkinter Populating Treeview. Afficher tous les articles

Python Tkinter Populate Treeview From List

How To Populate a Tkinter TreeView From a List Using Python

Python Tkinter Populate Treeview From List


import tkinter as tk
from tkinter import *
from tkinter import ttk


root = Tk()


data = [
[1,"AAA","BBB","[email protected]",17],
[3,"EEE","FFF","[email protected]",91],
[4,"GGG","HHH","[email protected]",47],
[7,"MMM","NNN","[email protected]",25],
[8,"PPP","QQQ","[email protected]",43],
[9,"RRR","SSS","[email protected]",94],
]


trv = ttk.Treeview(root, columns=(1,2,3,4,5), show='headings')
trv.column(1, anchor='center', width=100)
trv.column(2, anchor='center', width=100)
trv.column(3, anchor='center', width=100)
trv.column(4, anchor='center', width=100)
trv.column(5, anchor='center', width=100)

trv.heading(1, text='ID')
trv.heading(2, text='First Name')
trv.heading(3, text='Last Name')
trv.heading(4, text='Email')
trv.heading(5, text='Age')

# create a function to display data in treeview
def displayData():
for row in data:
trv.insert('',END, values=row)


displayData()


trv.grid(row=0, column=0, padx=10, pady=10)


root.mainloop()

OUTPUT:

Python Tkinter Populate Treeview
Python Tkinter Populating Treeview