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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
| import os.path
import pickle
import tkinter.ttk as ttk
from tkinter import *
import shutil # Pour save des fichiers
# ____________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________
# Création de l'instance Tk
fen1 =Tk()
# ____________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________
# Les constantes
NOMDOS = os.getcwd() # Nom du dossier courant
NOMFIC = "0_Codes_LesClasses.txt" # Nom du fichier des codes
# ____________________________________________________________________________________________________________________
# liste
global gens
gens = []
# ____________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________
# Les fenêtres d'alertes
def btMsgBox(msg, titre):
"""MsgBox d'alerte, un seul choix : fermeture"""
varCoulPrinc = "Slate Gray"
fenMsgBox = Toplevel()
fenMsgBox.title(titre)
fenMsgBox.configure(bg=varCoulPrinc)
fenMsgBox.geometry('300x200+670+400')
# Objets
objMsgBox1 = Label(fenMsgBox, height=10, width=30, text=titre + "\n \n" + msg, bg=varCoulPrinc)
bouValidMsgBox = Button(fenMsgBox, text="VALID", bg="Cornflower Blue", command=fenMsgBox.destroy)
# positionnements des objets
objMsgBox1.pack(side=TOP)
bouValidMsgBox.pack(side=BOTTOM)
# *************************************
# Réception d'événements pour fenMsgBox
# *************************************
fenMsgBox.mainloop()
# ____________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________
# Fonction de validation de création de nouvelle fiche
def foncBoutNewValid():
""" Bouton de validation permettant de créer une nouvelle fiche"""
# Récupération des données de la fenêtre NEW (création d'un nouveau code)
prenom = ObjNewNom.get()
nomfami = ObjNewCode.get()
datenaiss = objNewRenseig.get()
# Récupération de la case à cocher
if varTruqueeO_N2.get():
courriel ="Oui" # Coché
else:
courriel ="Non" # Pas coché
# Création du msg de création
titre = "INFORMATION !"
msg = "Nouvelle fiche crée pour : \n Logging : " + prenom + "\n nomfami : " + nomfami + "\n Renseignement : " + datenaiss + "\nTruqué (O/N) : " + str(courriel)
btMsgBox(msg, titre)
# Concatenation des listes
fiche_nouvo=[prenom, nomfami, datenaiss, courriel]
gens.append (fiche_nouvo)
# Trie de la liste par logging [2]
gens2 = sorted (gens, key=lambda gens: gens[2])
# Enregistrement
with open (NOMFIC, "wb") as fichier:
pickle.dump (gens2, fichier)
# Mise a jour liste déroulante
print(gens2)
objListDeroul.configure (values=gens2)
objListDeroul.update_idletasks # C'est là qu'est le problème
def foncBoutNew():
# *********************************
# CREATION DES ELEMENTS FENETRE NEW
# *********************************
# Création de la fenêtre nouveau code
varCoulPrinc = "Dark Olive Green"
varCoulSecon = "Olive Drab"
fenNew = Toplevel()
fenNew.title("Nouveau code")
fenNew.configure(bg=varCoulPrinc)
fenNew.geometry('480x250+600+400')
# Déclaration en global des variables de saisie
global ObjNewNom
global ObjNewCode
global objNewRenseig
global varTruqueeO_N2
#global objLabelNew2
varTruqueeO_N2 =IntVar()
# Création de la frame
objFrameNew = LabelFrame(fenNew, text="Nouveau code", padx=5, pady=10, bg=varCoulPrinc)
objFrameNew.pack(fill="both", expand="yes", padx=5, pady=10)
# ******************************
# Créa des objets dans la frames
# ******************************
# labels
objLabelNew1 = Label(objFrameNew, height=1, width=20, text="Logging :", bg=varCoulPrinc)
objLabelNew2 = Label(objFrameNew, height=1, width=20, text="Code :", bg=varCoulPrinc)
objLabelNew3 = Label(objFrameNew, height=1, width=40, text="Renseignements", bg=varCoulPrinc)
# Créa objet nom
ObjNewNom = Entry(objFrameNew, width=24, bg=varCoulSecon)
# Créa objet Code
ObjNewCode = Entry(objFrameNew, width=24, bg=varCoulSecon)
# Créa objet bouton truquée
# varTruqueeNew_O_N = 10 # initialisation de la variable cochée ou pas
bouton0 = Checkbutton(objFrameNew, variable=varTruqueeO_N2, bg=varCoulPrinc ,text="Truquée ?", activebackground=varCoulPrinc) # varTruqueeNew_O_N : 0= décochée, 1=cochée
# Créa objet renseignements
objNewRenseig = Entry(objFrameNew, width=52, bg=varCoulSecon)
# *****************************************
# Positionnement des objets dans la frames
# *****************************************
# labels
objLabelNew1.grid(column=0, row=0, padx=10)
objLabelNew2.grid(column=2, row=0, padx=5)
objLabelNew3.grid(column=0, row=3, columnspan=3)
# Objets
ObjNewNom.grid(column=0, row=1, padx=10, pady=(0 ,20))
ObjNewCode.grid(column=2, row=1, padx=10, pady=(0 ,20))
bouton0.grid(column=3, row=1, padx=(0, 5), pady=(0, 20))
objNewRenseig.grid(column=0, row=4, columnspan=3, padx=10, pady=(0 ,20))
# *******************************
# *Boutons externes ************
# *******************************
# Créa bouton Validation
bouValidNew = Button(fenNew, text="VALID", bg="Cornflower Blue", command=foncBoutNewValid)
# Créa bouton Annuler
bouQuitNew = Button(fenNew, text="EXIT", bg="Cornflower Blue", command=fenNew.destroy)
# Positionnement des boutons externes
bouValidNew.pack(side=LEFT)
bouQuitNew.pack(side=RIGHT)
# Focus sur la case Nom
ObjNewNom.focus()
# **********************************
# Réception d'événements pour fenNew
# **********************************
fenNew.mainloop()
# ____________________________________________________________________________________________________________________
# ____________________________________________________________________________________________________________________
# MAIN : Lancement du programme Principal
# ____________________________________________________________________________________________________________________
# Variables locales
varCoulPrinc = "Sea Green"
varCoulSecon = "Medium Sea Green"
# ____________________________________________________________________________________________________________________
# Création fenêtre principale
fen1.geometry('620x400+600+325')
fen1.title("Codes")
fen1.configure(bg = varCoulPrinc)
# ____________________________________________________________________________________________________________________
# # Créa objet logging
Label(fen1 ,height=1 ,width=30, text="Logging", bg=varCoulPrinc).grid(row=0, sticky=W, padx=5, pady=(5 ,0))
objLogging=Label(fen1 ,height=1 ,width=30, bg=varCoulSecon, relief=SUNKEN)
# Créa objet code
Label(fen1 ,height=1 ,width=30, text="Code", bg=varCoulPrinc).grid(row=0 ,column=1, padx=(40 ,5), pady=(5 ,0))
objCode = Label(fen1 ,height=1 ,width=30, bg=varCoulSecon, relief=SUNKEN)
# Créa objet bouton truquée
varTruqueeO_N =0 # initialisation de la variable cochée ou pas
objTruquee = Checkbutton(fen1, variable=varTruqueeO_N, bg=varCoulPrinc, text="Truquée ?", activebackground=varCoulPrinc) # varTruqueeO_N : 0= décochée, 1=cochée
# Créa objet renseignements
Label(fen1 ,height=1 ,width=68, text="Renseignements", bg=varCoulPrinc).grid(row=2 ,column=0, padx=5, columnspan=2, sticky=W, pady=(15 ,0))
objRenseig = Label(fen1 ,height=5 ,width=68, bg=varCoulSecon, relief=SUNKEN)
# Créations - Boutons hors-frames
bouNew =Button(fen1, bg="Cornflower Blue", text="NEW", command=foncBoutNew)
bouQuit =Button(fen1, bg="Cornflower Blue", text="EXIT", command=fen1.destroy)
# Position des labels ou est inscrit les codes
objLogging.grid(row=1, sticky=W, padx=5, pady=(0 ,5))
objCode.grid(row=1 ,column=1, padx=(40 ,5), pady=(0 ,5))
objTruquee.grid(row=1 ,column=2, padx=(0 ,5), pady=(0 ,5))
objRenseig.grid(row=3 ,padx=5, columnspan=2, sticky=W, pady=(0 ,5))
# ____________________________________________________________________________________________________________________
# Créations - liste déroulante
# Récup des logging seulement pour la liste déroulante
lstCode =[] # verif crois que ça sert a rien
# Verif que le fichier existe
if os.path.exists(NOMFIC):
# Existe, on le lit
with open (NOMFIC, "rb") as fichier:
gens = pickle.load (fichier)
else:
# Existe pas : on le crée
gens=[]
with open (NOMFIC, "wb") as fichier:
pickle.dump (gens, fichier)
# Création de la liste
lstCodeActuel = []
for e in enumerate(gens):
lstCodeActuel.append(e[1][0])
# Création de la liste déroulante
objListDeroul = ttk.Combobox(fen1, values=lstCodeActuel, width=24) # Récup des valeurs : logging
# ____________________________________________________________________________________________________________________
# Position des Liste déroulante
objListDeroul.grid(row=9 ,column=0, sticky=E, pady=(5))
# Position des boutons externes
bouNew.grid(row=10 ,column=0)
bouQuit.grid(row=10 ,column=1)
# ____________________________________________________________________________________________________________________
# Réception d'événements
fen1.mainloop() |
Partager