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
   | from tkinter import *
from datetime import *
fenetre = Tk()
ctc=[[],[],[]]
 
Frame1 = Frame(fenetre, bg="red", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
 
Frame2 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 2, padx=5, pady=5)
 
Frame3 = Frame(fenetre) #frame d'entrée de données
 
Frame4 = Frame(fenetre)
 
def ajt():
    Frame3.grid(row = 1, column = 0)
    Label1 = Label(Frame3, text = "Informations du contact")
    Label1.grid(row = 0, column = 0, columnspan = 1)
    nomLabel = Label(Frame3, text = "Nom ? ")
    nomEntry = Entry(Frame3)
    nomLabel.grid(row = 1, column = 0)
    nomEntry.grid(row = 1, column = 1)
    nomEntry.focus()
    prenomLabel = Label(Frame3, text = "Prénom ? ")
    prenomEntry = Entry(Frame3)
    prenomLabel.grid(row = 2, column = 0)
    prenomEntry.grid(row = 2, column = 1)
    prenomEntry.focus()
    numLabel = Label(Frame3, text = "Numéro ? ")
    numEntry = Entry(Frame3)
    numLabel.grid(row = 3, column = 0)
    numEntry.grid(row = 3, column = 1)
    numEntry.focus()
    submitCommand = lambda event = None: ajtResult(ctc, nomEntry, prenomEntry, numEntry)
    submitButton = Button(Frame3, text = "Valider", command = submitCommand)
    fenetre.bind('<Return>', lambda e: e.widget.event_generate('<Tab>'))
    submitButton.grid(row = 4, column = 0, columnspan = 1)
 
def ajtResult(ctc, ent1, ent2, ent3):
    nom = ent1.get()
    prenom = ent2.get()
    num = ent3.get()
    ctc[0].append(nom), ctc[1].append(prenom), ctc[2].append(num)
    rows = [[group[n] for group in ctc] for n in range(len(ctc[0]))]
    file = open("contacts.txt", "a")
    file.write("\n".join([repr(x) for x in rows]))
    file.close()
    ctc=[[],[],[]]
 
def rch():
    Frame3.grid(row = 1, column = 2)
    Label1 = Label(Frame3, text = "Code 60 déclenché ")
    Label1.grid(row = 2, column = 2, columnspan = 2)
    c60fLabel = Label(Frame3, text = "Fin de code 60 ? ")
    c60fEntry = Entry(Frame3)
    c60fLabel.grid(row = 3, column = 2, columnspan = 2)
    c60fEntry.grid(row = 4, column = 2, columnspan = 2)
 
Button(Frame1, text="Ajout Contact", command=ajt).pack(padx=300, pady=100)
 
Button(Frame2, text="Recherche Contact", command=rch).pack(padx=300, pady=100) | 
Partager