0% found this document useful (0 votes)
3 views

code_form-1

This document is a Python script that creates a Tkinter GUI for registering user data into a SQLite database. It includes functions for inserting data, creating the main window, and setting up input fields and buttons. The application ensures that required fields are filled before saving the data and provides success or error messages accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

code_form-1

This document is a Python script that creates a Tkinter GUI for registering user data into a SQLite database. It includes functions for inserting data, creating the main window, and setting up input fields and buttons. The application ensures that required fields are filled before saving the data and provides success or error messages accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import tkinter as tk

from tkinter import *


from tkinter import messagebox
import sqlite3

#Creation de la base de donnees et de la table


conn = sqlite3.connect('DataBases/database1.db')
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS utilisateur (id INTEGER PRIMARY KEY
AUTOINCREMENT, nom TEXT, prenom TEXT,'
'classe TEXT, dateN TEXT, matricule TEXT)')
conn.commit()

# Fonction pour inserer les donnees dans la table


def inserer_donnees():
nom = entry_nom.get()
prenom = entry_prenom.get()
classe = entry_classe.get()
date = entry_dateN.get()
matricule = entry_id.get()

if nom and matricule and classe:


cursor.execute('INSERT INTO utilisateur (nom, prenom, classe, dateN,
matricule) VALUES(?,?,?,?,?)',
(nom, prenom, classe, date, matricule))
conn.commit()
messagebox.showinfo("SUCCES", "Les données ont été enregistrées!")

# Vider les zone de saisie


entry_nom.delete(0, END)
entry_prenom.delete(0, END)
entry_classe.delete(0, END)
entry_dateN.delete(0, END)
entry_id.delete(0, END)

else:
messagebox.showerror("ERREUR", "Veuillez remplir tous les champs!")

#creation de la fenetre principale


fenetre = Tk()
fenetre.title('PAGE ENREGISTREMENT')
fenetre.geometry('600x600')
fenetre.iconbitmap("logo/ui-element.ico")
fenetre.minsize(600, 600)
fenetre.maxsize(800, 800)
fenetre.configure(bg='black')

#Creation du frame principal


main_frame = Frame(fenetre, padx=10, pady=10, bg='#ced6e0')
main_frame.pack(expand=1)

main_canvas = Canvas(main_frame, width=500, height=400, bg='#ced6e0')


main_canvas.grid(column=0, row=1)

#Creation du frame pour afficher la base de donnees


frame_data = Frame(fenetre, bg='#f1f2f6', relief=SUNKEN)
frame_data.pack(padx=20, pady=10, side=RIGHT, expand=YES)

#Creation des scrollbar


xbar = Scrollbar(main_frame, orient=HORIZONTAL)
xbar.grid(column=0, row=0, sticky=NW+SE)
ybar = Scrollbar(main_frame, orient=VERTICAL)
ybar.grid(column=1, row=1, sticky=NW+SE)

#connecter les scollbar


main_canvas.configure(xscrollcommand=xbar.set, yscrollcommand=ybar.set,
scrollregion=(0, 0, 2000, 1000))
xbar.configure(command=main_canvas.xview)
ybar.configure(command=main_canvas.yview)
main_canvas.bind('<Configure>',
lambda e:
main_canvas.configure(scrollregion=main_canvas.bbox("all")))
second_frame = Frame(main_canvas, bg='#f1f2f6')
main_canvas.create_window((0, 0), window=second_frame, anchor='nw')

#Creation des label


label_font = ("Century Gothic", 10)

label_nom = Label(second_frame, text="Nom :*", fg='black', padx=10, pady=20,


font=label_font)
label_prenom = Label(second_frame, text="Prénom :", fg='black', padx=10, pady=20,
font=label_font)
label_id = Label(second_frame, text="Matricule :*", fg='black', padx=10, pady=20,
font=label_font)
label_classe = Label(second_frame, text="Classe :*", fg='black', padx=10, pady=20,
font=label_font)
label_dateN = Label(second_frame, text="Date de Naissance :", fg='black', padx=10,
pady=20, font=label_font)

#Affichage des label


label_nom.grid(column=0, row=0)
label_prenom.grid(column=0, row=1)
label_id.grid(column=0, row=2)
label_classe.grid(column=0, row=3)
label_dateN.grid(column=0, row=4)

#Creation des zones de saisie (Entry)


entry_nom = Entry(second_frame, width=40, font=("Consolas", 15, 'bold'))
entry_prenom = Entry(second_frame, width=40, font=("Consolas", 15, 'bold'))
entry_id = Entry(second_frame, width=40, font=("Consolas", 15, 'bold'))
entry_classe = Entry(second_frame, width=40, font=("Consolas", 15, 'bold'))
entry_dateN = Entry(second_frame, width=40, font=("Consolas", 15, 'bold'))

#Afficher les zones de saisie


entry_nom.grid(column=1, row=0, columnspan=2)
entry_prenom.grid(column=1, row=1, columnspan=2)
entry_id.grid(column=1, row=2, columnspan=2)
entry_classe.grid(column=1, row=3, columnspan=2)
entry_dateN.grid(column=1, row=4, columnspan=2)

#Creation des boutons


button_font = ("Century Gothic", 12)
btn_save = Button(second_frame, text='ENREGISTRER', font=button_font, bd=2,
bg='#2f3542', width=15, height=1,
fg='white', command=inserer_donnees)
#Afficher Boutons
btn_save.grid(column=2, row=7)

fenetre.mainloop()

You might also like