bonjour, je suis débutant sur python, mais vraiment débutant. j'essaye de créer une sorte de formulaire à remplir.
donc j'ai 3 scripts, chacun ouvre une fenêtre. Lorsque je clique sur Run, sur chaque script individuellement, ça fonctionne parfaitement.
Mais dès que j'essaye d'ouvrir la fenêtre 2 à partir de la fenêtre 1 et la fenêtre 3 à partir de la fenêtre 2, là ça ne fonctionne plus bien et j'ai pleins de bugs. Du genre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
return self.func(*args)
  File "<string>", line 18, in buttonCreer
NameError: name 'window' is not defined"
ça serait super si vous pouviez m'aider, déjà en corrigeant mes scripts puis en m'expliquant le principe de l'erreur.

script1 :

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
from tkinter import *
from tkinter import messagebox
 
 
def ok():
    uname = e1.get()
    password = e2.get()
 
    if(uname == "" and password == ""):
        messagebox.showinfo("", "Blank Not allowed")
 
    elif(uname == "admin" and password == "admin"):
        messagebox.showinfo("","Login Success")
        root.destroy()
        exec(open("chercherPatient.py").read())
 
    else:
        messagebox.showinfo("","Incorrent Username and Password")
 
 
root = Tk()
root.title("Login")
root.geometry("300x200")
root.iconbitmap("image\leH.ico")
root.title("doc login")
global e1
global e2
 
Label(root, text="UserName").place(x=10, y=10)
Label(root, text="Password").place(x=10, y=40)
 
e1 = Entry(root)
e1.place(x=140, y=10)
 
e2 = Entry(root)
e2.place(x=140, y=40)
e2.config(show="*")
 
 
Button(root, text="Login", command=ok, height=3, width=13).place(x=10, y=100)
 
root.mainloop()
script2

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
from tkinter import *
import tkinter as tk
 
 
#creer une premiere fenetre
window = Tk()
 
 
#personnalier la fenetrer
window.title("Patient")
window.geometry("720x480")
window.minsize(480, 360)
window.iconbitmap("image\leH.ico")
window.config(background="white")
 
 
def buttonCreer():
    window.destroy()
    exec(open("dossierPatient.py").read())
 
#creation dimage
photo = PhotoImage(file="image\logoHermes3.png")
label = Label(window, image=photo, bg="white")
label.pack(side="top")
 
 
#creer la frame nouveau patient
frameNouveau = Frame(window, bg="#F5CBA7", bd=1, relief=SUNKEN)
frameNouveau.pack(fill=X)
 
 
 
 
#titre Frame titre nouveau patient
label_title = Button(frameNouveau, text = "Creer nouveau patient", font=("Courrier", 15), fg="black", command=buttonCreer)
label_title.grid(row=0, column=2, padx= "200")
 
 
window.mainloop()
script 3

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
from tkinter import *
import tkinter as tk
from tkcalendar import DateEntry
from dateutil.relativedelta import relativedelta
from datetime import date, datetime
 
#creer une premiere fenetre
window = Tk()
 
#personnalier la fenetrer
window.title("Fiche Medicale")
window.geometry("720x480")
window.minsize(480, 360)
window.iconbitmap("image/leH.ico")
window.config(background="white")
 
 
#creation dimage
photo = PhotoImage(file="image/logoHermes3.png")
label = Label(window, image=photo, bg="white")
label.pack()
 
 
#creer la frame pour indentifiants
frame = Frame(window, bg="#F5CBA7", bd=1, relief=SUNKEN)
 
#titre Frame titre Identifiant
label_title = Label(frame, text = "identifiants patient", font= ("Courrier", 15),bg="#F5CBA7", fg = "black")
label_title.grid(row=0, column=0)
 
lmatricule = Label(frame, text="matricule",bg="#F5CBA7").grid(row=1, column=0)
ematricule = Entry(frame).grid(row=1,column=1)
lnom = Label(frame, text="nom",bg="#F5CBA7").grid(row=2, column=0)
enom = Entry(frame).grid(row=2,column=1)
lprenom = Label(frame, text="prenom",bg="#F5CBA7").grid(row=2, column=2)
eprenom = Entry(frame).grid(row=2,column=3)
lsex = Label(frame, text="sex",bg="#F5CBA7").grid(row=4, column=0)
rbsex1 = Radiobutton(frame, text = "Feminin", value = '1',bg="#F5CBA7").grid(row = 4, column = 1)
rbsex2 = Radiobutton(frame, text = "Masculin", value = '2',bg="#F5CBA7").grid(row = 4, column = 2)
rbsex3 = Radiobutton(frame, text = "Autre", value = '3',bg="#F5CBA7").grid(row = 4, column = 3)
lpays = Label(frame, text="pays",bg="#F5CBA7").grid(row=5, column=0)
epays = Entry(frame).grid(row=5,column=1)
lville = Label(frame, text="ville",bg="#F5CBA7").grid(row=5, column=2)
eville = Entry(frame).grid(row=5,column=3)
lcp = Label(frame, text="code postal",bg="#F5CBA7").grid(row=5, column=4)
ecp = Entry(frame).grid(row=5,column=5)
ladresse = Label(frame, text="adresse",bg="#F5CBA7").grid(row=6, column=0)
eadresse = Entry(frame).grid(row=6,column=1)
lnumero = Label(frame, text="numero de telephone",bg="#F5CBA7").grid(row=7, column=0)
enumero = Entry(frame).grid(row=7,column=1)
lemail = Label(frame, text="adresse mail",bg="#F5CBA7").grid(row=7, column=2)
eemail = Entry(frame).grid(row=7,column=3)
 
#ajouter date de naissance
sel = tk.StringVar() # declaring string variable
ldatedenaissance = Label(frame, text="date de naissance",bg="#F5CBA7").grid(row=3, column=0)
cal=DateEntry(frame,selectmode='day',textvariable=sel)
cal.grid(row=3,column=1,padx=20)
 
def my_upd(*args): # triggered when value of string varaible changes
    l1.config(text=sel.get()) # read and display date
 
 
def my_upd(*args): # triggered when value of string varaible changes
    if(len(sel.get())>4):
        l1.config(text=sel.get()) # read and display date
        dob = datetime.strptime(sel.get(),'%m/%d/%y')
        dt=date.today()
        dt3=relativedelta(dt,dob)
        l2.config(text="Dayes:" + str(dt3.days) +"\n Months:"+ str(dt3.months) + "\n Years:"+ str(dt3.years) )
        print("Dayes:",dt3.days," Months:",dt3.months," Years:", dt3.years)
 
 
l1=tk.Label(frame,bg='yellow')  # Label to display date
l1.grid(row=3,column=2)
 
l2=tk.Label(frame)  # Label to display date
l2.grid(row=3,column=3,padx=10)
 
sel.trace('w',my_upd) # on change of string variable
 
 
 
frame.pack(fill=X)
 
#afficher
window.mainloop()
merci de m'avoir lu