0% found this document useful (0 votes)
11 views3 pages

From Tkinter Import

This document is a Python script that uses Tkinter for a client management application connected to a MySQL database. It includes functions to create a database connection, initialize a client table, add clients, and clear input fields. The GUI allows users to enter client details and save them to the database, with error handling for duplicate emails.

Uploaded by

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

From Tkinter Import

This document is a Python script that uses Tkinter for a client management application connected to a MySQL database. It includes functions to create a database connection, initialize a client table, add clients, and clear input fields. The GUI allows users to enter client details and save them to the database, with error handling for duplicate emails.

Uploaded by

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

from tkinter import *

import mysql.connector
from tkinter import messagebox

def creer_connexion():
conn = mysql.connector.connect(
host="localhost",
user="root", # Remplacez par votre nom d'utilisateur MySQL
password="", # Remplacez par votre mot de passe MySQL
database="GESTIONCLIENT" # Remplacez par le nom de votre base de
données
)
return conn

def initialiser_bdd():
conn = creer_connexion()
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS client (
idCLIENT INT AUTO_INCREMENT PRIMARY KEY,
nomCLIENT VARCHAR(100) NOT NULL,
prenom VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE,
tel VARCHAR(15))''')
conn.commit()
conn.close()

def ajouter_client():
try:
conn = creer_connexion()
cur = conn.cursor()
cur.execute("INSERT INTO client (nomclient, prenom, email, tel)
VALUES (%s, %s, %s, %s)",
(entry_nom.get(), entry_prenom.get(),
entry_email.get(), entry_tel.get()))

conn.commit()
messagebox.showinfo("Succès", "Client ajouté avec succès!")
vider_champs()
except mysql.connector.IntegrityError:
messagebox.showerror("Erreur", "Cet email existe déjà!")
except Exception as e:
messagebox.showerror("Erreur", str(e))
finally:
conn.close()

def vider_champs():
entry_nom.delete(0, END)
entry_prenom.delete(0, END)
entry_email.delete(0, END)
entry_tel.delete(0, END)

# Initialisation de la BDD
initialiser_bdd()

# Création de l'interface
app = Tk()
app.title("Gestion Clients")
app.geometry("800x600")

Label(app,
text="Nom:",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,relief=GRO
OVE).grid(row=0, column=0, padx=10, pady=5, sticky=W)
entry_nom = Entry(app, width=30)
entry_nom.grid(row=0, column=1, padx=10, pady=5)

Label(app,
text="Prénom:",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,relief=
GROOVE).grid(row=1, column=0, padx=10, pady=5, sticky=W)
entry_prenom = Entry(app, width=30)
entry_prenom.grid(row=1, column=1, padx=10, pady=5)

Label(app,
text="Email:",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,relief=G
ROOVE).grid(row=2, column=0, padx=10, pady=5, sticky=W)
entry_email = Entry(app, width=30)
entry_email.grid(row=2, column=1, padx=10, pady=5)

Label(app,
text="Téléphone:",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,reli
ef=GROOVE).grid(row=3, column=0, padx=10, pady=5, sticky=W)
entry_tel = Entry(app, width=30)
entry_tel.grid(row=3, column=1, padx=10, pady=5)

btn_ajouter = Button(app,
text="Enregistrer",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,rel
ief=GROOVE, command=ajouter_client, width=15)
btn_ajouter.grid(row=4, column=1, pady=10)
btn_quiter = Button(app,
text="FERMER",font=("Arial",30,"bold"),bg="GREEN",fg="orange",bd=4,relief=G
ROOVE, command=quit, width=15)
btn_quiter.grid(row=5, column=1, pady=10)

app.mainloop()

You might also like