0% found this document useful (0 votes)
15 views1 page

Exo 1

Uploaded by

kaws doom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Exo 1

Uploaded by

kaws doom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import sqlite3

import tkinter as tk
from tkinter import ttk

# creation et connection a la bdd


connection = sqlite3.connect('D:\\project\\archive.db')
cursor = connection.cursor()

# creation de la table si elle existe pas elle la cree


create_table_pointeuse = '''
CREATE TABLE IF NOT EXISTS pointeuse (
id INTEGER PRIMARY KEY,
nom TEXT NOT NULL,
prenom TEXT NOT NULL,
date DATE NOT NULL
);
'''
cursor.execute(create_table_pointeuse)
connection.commit()
sample_data = [('Doe', 'John', '2024-11-01'),('Smith', 'Jane', '2024-11-02'),
('Brown', 'Charlie', '2024-11-03')]
cursor.executemany("INSERT INTO pointeuse (nom, prenom, date) VALUES (?, ?, ?)",
sample_data)

# recuperation de toutes lignes


def fetch_data():
cursor.execute("SELECT * FROM pointeuse")
rows = cursor.fetchall()
return rows

# Create main window


root = tk.Tk()
root.title("Pointeuse Table")

# Set up Treeview table


columns = ('ID', 'Nom', 'Prenom', 'Date')
tree = ttk.Treeview(root, columns=columns, show='headings')
tree.heading('ID', text='ID')
tree.heading('Nom', text='Nom')
tree.heading('Prenom', text='Prenom')
tree.heading('Date', text='Date')

# Set column widths


for col in columns:
tree.column(col, anchor='center', width=120)

# Insert data into the Treeview


rows = fetch_data()
for row in rows:
tree.insert('', tk.END, values=row)

tree.pack(fill=tk.BOTH, expand=True)

# Run the GUI application


root.mainloop()

# Close the database connection after the main loop ends


connection.close()

You might also like