Bonjour tout le monde,
J'aurai besoin d'un peu d'aide s'il vous plait sur un problème sur lequel je bloque.
En fait, j'utilise plusieurs script et un classe dans chacun de ses scripts.
Au niveau du 3éme script "créerDossier", il y a un formulaire patient qui s'enregistre sur MySQL, donc, une fois un patient sélectionné via son ID, je clique sur un bouton "ouvrir dossier" qui me mène au 4éme script "dossierPatient".
Le problème c'est que je n'arrive pas récupérer l'ID du 3éme script dans le 4éme script pour ouvrir la base de donnée relative au dit-patient.
J'ai bien sur chercher sur le net, j'ai utilisé la méthode qui m'a semblé correcte, qui est la suivant.
mais j'ai comme erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 import creerDossier f1 = creerDossier.PageTwo(self, parent) f2 =f1.searchDB(id)
AttributeError: 'PageTwo' object has no attribute 'searchDB'
Alors je vais partager avec vous mon code (raccourci), peut être que vous pourrez m'aider:
script 1 : le root:
script numéro 3 : creerDossier (le 2 n'étant pas pertienent):
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 import tkinter as tk # python 3 from tkinter import messagebox from chercherDossier import PageOne from creerDossier import PageTwo from dossierPatient import PageThree class SampleApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic") self.state("zoomed") self.iconbitmap("image/leH.ico") self.title("HERMES") # the container is where we'll stack a bunch of frames # on top of each other, then the one we want visible # will be raised above the others container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (StartPage, PageOne, PageTwo, PageThree): page_name = F.__name__ frame = F(parent=container, controller=self) self.frames[page_name] = frame # put all of the pages in the same location; # the one on the top of the stacking order # will be the one that is visible. frame.grid(row=0, column=0, sticky="nsew") self.show_frame("StartPage") def show_frame(self, page_name): '''Show a frame for the given page name''' frame = self.frames[page_name] frame.tkraise() class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller 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") controller.show_frame("PageOne") else: messagebox.showinfo("", "Incorrent Username and Password") user = tk.Label(self, text="UserName").grid(row=0, column=0) password = tk.Label(self, text="Password").grid(row=1, column=0) e1 = tk.Entry(self) e1.grid(row=0, column=1) e2 = tk.Entry(self) e2.grid(row=1, column=1) e2.config(show="*") frame1_btn = tk.Button(self, text="Login", command=ok, height=3, width=13).grid(row=2, column=1) if __name__ == "__main__": app = SampleApp() app.mainloop()
et le script 4 : dossierPatient, ou j'essaye de récupérer l'ID de la fonction "def searchDB():" de la classe "class PageTwo(tk.Frame):"
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
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 import mysql.connector from tkinter import * import tkinter as tk # python 3 from tkinter import ttk, messagebox import tkinterpp class PageTwo(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller mysqldb = mysql.connector.connect( host='localhost', user='root', password='*****', port='3306', database='hermes_sql' ) mycursor = mysqldb.cursor() def GetValue(event): ematricule.delete(0, END) enom.delete(0, END) eprenom.delete(0, END) row_id = listBox.selection()[0] select = listBox.set(row_id) ematricule.insert(0, select['id']) enom.insert(0, select['nom']) eprenom.insert(0, select['prenom']) def Add(): nom = enom.get() prenom = eprenom.get() mysqldb = mysql.connector.connect( host='localhost', user='root', password='*****', port='3306', database='hermes_sql' ) mycursor = mysqldb.cursor() try: sql = "INSERT INTO users (id,nom,prenom) " \ "VALUES (%s,%s, %s)" val = (0, nom, prenom) mycursor.execute(sql, val) mysqldb.commit() lastid = mycursor.lastrowid ematricule.delete(0, END) ematricule.insert(END, lastid) messagebox.showinfo("information", "Employee inserted successfully...") ematricule.delete(0, END) enom.delete(0, END) eprenom.delete(0, END) enom.focus_set() except Exception as e: print(e) mysqldb.rollback() mysqldb.close() def searchDB(): id = ematricule.get() mysqldb = mysql.connector.connect( host='localhost', user='root', password='*****', port='3306', database='hermes_sql' ) mycursor = mysqldb.cursor() try: sql = "select * from users where id = %s" val = (id,) mycursor.execute(sql, val) users = mycursor.fetchone() ematricule.delete(0, END) enom.delete(0, END) eprenom.delete(0, END) enom.focus_set() ematricule.insert(0, str(users[0])) enom.insert(0, str(users[1])) eprenom.insert(0, str(users[2])) except Exception as e: print(e) mysqldb.rollback() mysqldb.close() return id def vider_entry(): ematricule.delete(0, END) enom.delete(0, END) eprenom.delete(0, END) def show(): mycursor.execute("SELECT id,nom,prenom FROM users") users = mycursor.fetchall() print(users) for i, (id, nom, prenom) in enumerate(users, start=1): listBox.insert("", "end", values=(id,nom,prenom)) mysqldb.close() global ematricule global enom global eprenom # creer frame pour identifiant frame_ident = Frame(self, bg="#F5CBA7", bd=1, relief=SUNKEN) frame_ident.pack(fill=X) lmatricule = tk.Label(frame_ident, text="matricule", bg="#F5CBA7").grid(row=2, column=0) ematricule = tk.Entry(frame_ident) ematricule.grid(row=2, column=1) lnom = Label(frame_ident, text="nom", bg="#F5CBA7").grid(row=3, column=0) enom = tk.Entry(frame_ident) enom.grid(row=3, column=1) lprenom = tk.Label(frame_ident, text="prenom", bg="#F5CBA7").grid(row=3, column=2) eprenom = tk.Entry(frame_ident) eprenom.grid(row=3, column=3) # frame pout les bouttons frame_butt = Frame(self, bg="#F5CBA7", bd=1, relief=SUNKEN) frame_butt.pack(fill=X, pady=10) Button(frame_butt, text="créer dossier", command=Add, height=3, width=13).grid(row=0, column=0, padx=20) Button(frame_butt, text="chercher", command=searchDB, height=3, width=13).grid(row=0, column=3, padx=20) Button(frame_butt, text="ouvrir le dossier",command=lambda: controller.show_frame("PageThree"), height=3, width=13).grid(row=0, column=5, padx=20) # frame tableau frame_tab = Frame(self, bg="#F5CBA7", bd=1, relief=SUNKEN) frame_tab.pack(fill=X, pady=10) cols = ('id', 'nom', 'prenom', 'date de naissance', 'sex', 'pays', 'ville', 'code postal', 'adresse','numèro de telephone', 'adresse mail') listBox = ttk.Treeview(frame_tab, columns=cols, show='headings', selectmode='browse') for col in cols: listBox.heading(col, text=col) listBox.grid(row=1, column=0, columnspan=3) show() listBox.bind('<Double-Button-1>', GetValue)
merci de m'avoir lu
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 import mysql.connector from tkinter import * import tkinter as tk import creerDossier class PageThree(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller def lookDB(): #ici le problème####################le problème ##################################### f1 = creerDossier.PageTwo(self, parent) f2 =f1.searchDB(id) id = f2 #################################################################### mysqldb = mysql.connector.connect( host='localhost', user='root', password='****', port='3306', database='hermes_sql' ) mycursor = mysqldb.cursor() try: sql = "select * from users where id = %s" val = (id,) mycursor.execute(sql, val) users = mycursor.fetchone() ematricule.delete(0, END) enom.delete(0, END) eprenom.delete(0, END) enom.focus_set() ematricule.insert(0, str(users[0])) enom.insert(0, str(users[1])) eprenom.insert(0, str(users[2])) except Exception as e: print(e) mysqldb.rollback() mysqldb.close() global ematricule global enom global eprenom # creer frame pour identifiant frame_ident = Frame(self, bg="#F5CBA7", bd=1, relief=SUNKEN) frame_ident.pack(fill=X) # titre Frame titre Identifiant label_title = tk.Label(frame_ident, text="identifiants patient", font=("Courrier", 15), bg="#F5CBA7", fg="black") label_title.grid(row=1, column=0) lmatricule = tk.Label(frame_ident, text="matricule", bg="#F5CBA7").grid(row=2, column=0) ematricule = tk.Entry(frame_ident) ematricule.grid(row=2, column=1) lnom = Label(frame_ident, text="nom", bg="#F5CBA7").grid(row=3, column=0) enom = tk.Entry(frame_ident) enom.grid(row=3, column=1) lprenom = tk.Label(frame_ident, text="prenom", bg="#F5CBA7").grid(row=3, column=2) eprenom = tk.Entry(frame_ident) eprenom.grid(row=3, column=3) lookDB()
Partager