Bonjour je suis actuellement en classe de Terminale S spé ISN.
J'ai un problème dans mon programme que je souhaite présenter en fin d'année pour le BAC.
J'aimerais mettre une base de données à partir d'un fichier, je voudrais que l'on puisse créer un compte dans mon programme et que les identifiants soient enregistrés dans le fichier.
Cependant il y a un problème, tout fonctionne bien cependant les variables ne s'écrivent pas dans le fichier :/

C'est la première fois que j'écris sur un forum je ne sais donc pas comment mettre mon programme en lien ou l'intégrer de façon proprement :/
Pour accéder à l'endroit où le problème se situe, il faut cliquer sur le bouton "nouvel utilisateur", puis rentrer ce que l'on veut dans les 2 champs de saisie puis appuyer sur le bouton "Créer le compte" ^^.
Merci d'avance pour votre aide ^^

Le programme :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
from tkinter import *
from tkinter.messagebox import *
 
#Création Fonction Nouvel Utilisateur
def NouveauCompte():
    NEWWindow = Tk()
    NEWWindow.title("Création d'un nouveau compte")
    NEWWindow.geometry('800x600')
 
    #Création Fonction Destroy fenetre nouveau compte
    def DestoyNEW():
        NEWWindow.destroy()
 
    #Création Fonction Liste
    def recup():
        Fichier = open('test.txt','a')
        Fichier.write("\nLe nom d'utilisateur :\n")
        Fichier.write(str(NomUtilisateurNEW.get())+'\n')
        Fichier.write("Le mot de passe :\n")
        Fichier.write(str(MotdepasseNEW.get())+'\n')
        Fichier.close()
        NEWWindow.destroy()
 
    #Création Label Accueil Nouveau Compte
    Create = Label(NEWWindow, text = "Créer un compte\n Commencer l'apprentissage du code de la route avec Madame Framboise !", bg="#FFC0CB")
    Create.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Label Nom d'utilisateur
    NomUtilisateurNEWlabel = Label(NEWWindow, text = "Nom d'utilisateur", bg="#ADD8E6", relief=RAISED)
    NomUtilisateurNEWlabel.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Champ de saisie Nom Utilisateur
    NomUtilisateurNEW = StringVar()
    ChampNomNEW = Entry(NEWWindow, textvariable = NomUtilisateurNEW, bg ='white', fg='#DB7093')
    ChampNomNEW.focus_set()
    ChampNomNEW.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Label Mot de passe
    NEWMDP = Label(NEWWindow, text = "Mot de passe", bg="#ADD8E6", relief=RAISED)
    NEWMDP.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Champ de saisie MDP
    MotdepasseNEW = StringVar()
    ChampMDPNEW = Entry(NEWWindow, textvariable = MotdepasseNEW, show='*', bg ='white', fg='#DB7093')
    ChampMDPNEW.focus_set()
    ChampMDPNEW.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Bouton Créer le compte
    CreateNEW = Button(NEWWindow, text ='Créer le compte', command=recup)
    CreateNEW.pack(side = TOP, padx = 5, pady = 5)
 
    #Création Bouton Déjà un compte
    Already = Button(NEWWindow, text ='Vous avez déjà un compte ?', command=DestoyNEW)
    Already.pack(side = TOP, padx = 5, pady = 5)
 
#Création Fonction Vérification MDP et Nom d'utilisateur
def Verification():
    if Motdepasse.get() == MotdepasseNEW.get() and NomUtilisateur.get() == NomUtilisateurNEW.get():
        # le mot de passe est bon : on affiche une boîte de dialogue puis on ferme la fenêtre
        showinfo('Résultat','Mot de passe correct.\nBienvenue !')
        MainWindow.destroy()
        HomeWindow = Tk()
        HomeWindow.title("Accueil")
        HomeWindow.geometry('800x600')
    else:
        # le mot de passe est incorrect : on affiche une boîte de dialogue
        showwarning('Erreur',"Mot de passe ou nom d'utilisateur incorrect.\nVeuillez recommencer !")
        Motdepasse.set('')
        NomUtilisateur.set('')
 
#Création fenêtre principal
MainWindow = Tk()
MainWindow.title("Ecran de connexion")
MainWindow.geometry('1100x600')
 
#Création Frame Login
Login = Frame(MainWindow, bg="#87CEFA", padx=20, pady=20)
Login.pack(fill="both", expand="yes", side = RIGHT)
 
#Création Frame Image
Image = Frame(MainWindow, bg ="#ADD8E6", padx=20, pady=20, width = 820, height = 600)
Image.pack_propagate(False)
Image.pack(side = LEFT)
 
#Création Label Nom Utilisateur
Nom = Label(Login, text = "Nom d'utilisateur", bg="#ADD8E6", relief=RAISED)
Nom.pack(side = TOP, padx = 5, pady = 5)
 
#Création Champ de saisie Nom Utilisateur
NomUtilisateur= StringVar()
ChampNom = Entry(Login, textvariable = NomUtilisateur, bg ='white', fg='#4682B4')
ChampNom.focus_set()
ChampNom.pack(side = TOP, padx = 5, pady = 5)
 
#Création Label MDP
MDP = Label(Login, text = 'Mot de passe ', bg="#ADD8E6", relief=RAISED)
MDP.pack(side = TOP, padx = 5, pady = 5)
 
#Création Champ de saisie MDP
Motdepasse= StringVar()
ChampMDP = Entry(Login, textvariable = Motdepasse, show='*', bg ='white', fg='#4682B4')
ChampMDP.focus_set()
ChampMDP.pack(side = TOP, padx = 5, pady = 5)
 
#Création Bouton Valider Nom Utilisateur et MDP
Valider = Button(Login, text ='Valider', command = Verification)
Valider.pack(side = TOP, padx = 5, pady = 5)
 
#Création Bouton Nouvel Utilisateur
NEW = Button(Login, text ='Nouvel Utilisateur', command = NouveauCompte)
NEW.pack(side = TOP, padx = 5, pady = 5)
 
#Création Image
photo=PhotoImage(file="Image Voiture + Framboise Login Screen.png")
fond=Canvas(Image,width=820,height=600,bg="white")
fond.create_image(0,0,image=photo, anchor=NW)
fond.pack(side=TOP)
 
MainWindow.mainloop()