· 6 years ago · Jun 04, 2019, 05:48 PM
1import sqlite3
2from tkinter import *
3
4root = Tk()
5root.title("моя база")
6root.geometry("1000x700")
7
8
9def all():
10 root2 = Tk()
11 root2.title("моя база")
12 root2.geometry("300x300")
13
14 def a2():
15 root3 = Tk()
16 root3.title("моя база")
17 root3.geometry("350x350")
18 lbl3 = Label(root3, text="Введите впорос:")
19 lbl3.pack()
20 textbox3 = Entry(root3, width=50)
21 textbox3.focus_set()
22 textbox3.pack()
23 lbl4 = Label(root3, text="1 вариант ответа ответа:")
24 lbl4.pack()
25 textbox4 = Entry(root3, width=30)
26 textbox4.pack()
27 lbl4 = Label(root3, text="2 вариант ответа ответа:")
28 lbl4.pack()
29 textbox5 = Entry(root3, width=30)
30 textbox5.pack()
31 lbl4 = Label(root3, text="3 вариант ответа ответа:")
32 lbl4.pack()
33 textbox6 = Entry(root3, width=30)
34 textbox6.pack()
35 lbl4 = Label(root3, text="Введите номер верного ответа:")
36 lbl4.pack()
37 textbox7 = Entry(root3, width=30)
38 textbox7.pack()
39
40 def lol():
41 p = 1
42 s = 2
43 l = 3
44 d = []
45 d1 = [textbox3.get(), s, l]
46 d.append(d1)
47 c = []
48 c1 = [s, textbox4.get(), textbox5.get(), textbox6.get(), textbox7.get(), s, s, s, s]
49 c.append(c1)
50 conn = sqlite3.connect('228.db')
51 cursor = conn.cursor()
52 cursor.execute('CREATE TABLE IF NOT EXISTS sozd1(vopr TEXT,vopr2 text,vopr3 text) ')
53 conn.commit()
54 cursor.execute(
55 'CREATE TABLE IF NOT EXISTS sozd2(otv1 text,otv2 text,otv3 text,otv4 text,prav integer,otv22 text,otv33 text,otv44 text,prav1 integer )')
56 for d1_unit in d:
57 cursor.execute('INSERT INTO sozd1 VALUES(?,?,?)', d1_unit)
58 for c1_unit in c:
59 cursor.execute('INSERT INTO sozd2 VALUES(?,?,?,?,?,?,?,?,?)', c1_unit)
60 cursor.execute('SELECT vopr FROM sozd1 ')
61 results1 = cursor.fetchall()
62 cursor.execute('SELECT * FROM sozd2')
63 results2 = cursor.fetchall()
64 print(results1)
65 print(results2)
66 conn.commit()
67 conn.close()
68 all()
69
70 button1 = Button(root3, text="ок", command=lol)
71 button1.pack()
72 button4.pack()
73
74 def a3():
75 root3 = Tk()
76 root3.title("моя база")
77 root3.geometry("350x350")
78 lbl3 = Label(root3, text="Введите впорос:")
79 lbl3.pack()
80 textbox3 = Entry(root3, width=50)
81 textbox3.focus_set()
82 textbox3.pack()
83 lbl4 = Label(root3, text="1 вариант ответа ответа:")
84 lbl4.pack()
85 textbox4 = Entry(root3, width=30)
86 textbox4.pack()
87 lbl4 = Label(root3, text="2 вариант ответа ответа:")
88 lbl4.pack()
89 textbox5 = Entry(root3, width=30)
90 textbox5.pack()
91 lbl4 = Label(root3, text="3 вариант ответа ответа:")
92 lbl4.pack()
93 textbox6 = Entry(root3, width=30)
94 textbox6.pack()
95 lbl4 = Label(root3, text="Введите номер верного ответа:")
96 lbl4.pack()
97 textbox7 = Entry(root3, width=30)
98 textbox7.pack()
99
100 def lol():
101 p = 1
102 s = 2
103 l = 3
104 d = []
105 d1 = [s, s, textbox3.get()]
106 d.append(d1)
107 c = []
108 c1 = [s, s, s, s, s, textbox4.get(), textbox5.get(), textbox6.get(), textbox7.get(), ]
109 c.append(c1)
110 conn = sqlite3.connect('228.db')
111 cursor = conn.cursor()
112 cursor.execute('CREATE TABLE IF NOT EXISTS sozd1(vopr TEXT,vopr2 text,vopr3 text) ')
113 conn.commit()
114 cursor.execute(
115 'CREATE TABLE IF NOT EXISTS sozd2(otv1 text,otv2 text,otv3 text,otv4 text,prav integer,otv22 text,otv33 text,otv44 text,prav1 integer)')
116 for d1_unit in d:
117 cursor.execute('INSERT INTO sozd1 VALUES(?,?,?)', d1_unit)
118 for c1_unit in c:
119 cursor.execute('INSERT INTO sozd2 VALUES(?,?,?,?,?,?,?,?,?)', c1_unit)
120 cursor.execute('SELECT vopr FROM sozd1 ')
121 results1 = cursor.fetchall()
122 cursor.execute('SELECT * FROM sozd2')
123 results2 = cursor.fetchall()
124 print(results1)
125 print(results2)
126 conn.commit()
127 conn.close()
128 all()
129
130 button1 = Button(root3, text="ок", command=lol)
131 button1.pack()
132
133 button2 = Button(root2, text="2 тип", command=a2)
134 button2.pack()
135 button2 = Button(root2, text="1 тип", command=a1)
136 button2.pack()
137 button2 = Button(root2, text="3 тип", command=a3)
138 button2.pack()
139
140
141def a1():
142 root3 = Tk()
143 root3.title("моя база")
144 root3.geometry("350x350")
145 lbl3 = Label(root3, text="Введите впорос:")
146 lbl3.pack()
147 textbox1 = Entry(root3, width=50)
148 textbox1.focus_set()
149 textbox1.pack()
150 lbl4 = Label(root3, text="Введите ответ:")
151 lbl4.pack()
152 textbox2 = Entry(root3, width=30)
153 textbox2.pack()
154
155 def lol1():
156 p = 1
157 s = 2
158 l = 3
159 a = []
160 a1 = [s, textbox1.get(), s]
161 a.append(a1)
162 b = []
163 b1 = [textbox2.get(), s, s, s, s, s, s, s, s]
164 b.append(b1)
165 conn = sqlite3.connect('228.db')
166 cursor = conn.cursor()
167 cursor.execute('CREATE TABLE IF NOT EXISTS sozd1(vopr TEXT,vopr2 text,vopr3 text) ')
168 conn.commit()
169 cursor.execute(
170 'CREATE TABLE IF NOT EXISTS sozd2(otv1 text,otv2 text,otv3 text,otv4 text,prav integer,otv22 text,otv33 text,otv44 text,prav1 integer)')
171 for a1_unit in a:
172 cursor.execute('INSERT INTO sozd1 VALUES(?,?,?)', a1_unit)
173 for b1_unit in b:
174 cursor.execute('INSERT INTO sozd2 VALUES(?,?,?,?,?,?,?,?,?)', b1_unit)
175 cursor.execute('SELECT vopr2 FROM sozd1 ')
176 results1 = cursor.fetchall()
177 cursor.execute('SELECT otv1 FROM sozd2 ')
178 results2 = cursor.fetchall()
179 print(results1)
180 print(results2)
181 conn.commit()
182 conn.close()
183 all()
184
185 button1 = Button(root3, text="ок", command=lol1)
186 button1.pack()
187
188
189global k
190k = 0
191global f
192f = 0
193global p
194p = 0
195global e
196e = 0
197
198
199def end():
200 global k
201 if k == 0:
202 root.destroy()
203 s = 0
204 conn = sqlite3.connect('228.db')
205 cursor = conn.cursor()
206 cursor.execute('SELECT vopr FROM sozd1 ')
207 results3 = cursor.fetchall()
208 for i in results3:
209 s=s+1
210 if (k>=s):
211 fff()
212 if (results3[k] != ('2',)):
213 root3 = Tk()
214 root3.title("моя база2")
215 root3.geometry("1000x1000")
216 cursor.execute('SELECT vopr3 FROM sozd1 ')
217 results34 = cursor.fetchall()
218 print(results34)
219 cursor.execute('''SELECT otv2 FROM sozd2 ''')
220 results4 = cursor.fetchall()
221 cursor.execute('''SELECT otv3 FROM sozd2 ''')
222 results5 = cursor.fetchall()
223 cursor.execute('''SELECT otv4 FROM sozd2 ''')
224 results6 = cursor.fetchall()
225 cursor.execute('''SELECT otv22 FROM sozd2 ''')
226 results7 = cursor.fetchall()
227 cursor.execute('''SELECT otv33 FROM sozd2 ''')
228 results8 = cursor.fetchall()
229 cursor.execute('''SELECT otv44 FROM sozd2 ''')
230 cursor.execute('''SELECT prav FROM sozd2 ''')
231 results88 = cursor.fetchall()
232 lbl1 = Label(root3, text="")
233 lbl1.pack(anchor=W)
234 lbl1['text'] = results3[k]
235 cvar1 = StringVar()
236 cvar1.set(0)
237 c1 = Checkbutton(root3, text=results4[k], variable=cvar1, onvalue="(1,)", offvalue=0)
238 c1.pack(anchor=W)
239 cvar2 = StringVar()
240 cvar2.set(0)
241 c2 = Checkbutton(root3, text=results5[k], variable=cvar2, onvalue="(2,)", offvalue=0)
242 c2.pack(anchor=W)
243 cvar3 = StringVar()
244 cvar3.set(0)
245 c3 = Checkbutton(root3, text=results6[k], variable=cvar3, onvalue="(3,)", offvalue=0)
246 c3.pack(anchor=W)
247 label1 = Label(text=str(cvar1.get()))
248 label1.pack()
249 label2 = Label(text=str(cvar2.get()))
250 label2.pack()
251 label3 = Label(text=str(cvar3.get()))
252 label3.pack()
253
254 def skk(*args):
255 label1.config(text=str(cvar1.get()))
256 label2.config(text=str(cvar2.get()))
257 label3.config(text=str(cvar3.get()))
258
259 cvar1.trace('w', skk)
260 cvar2.trace('w', skk)
261 cvar3.trace('w', skk)
262 else:
263 k=k+1
264 end()
265
266 def xxx():
267 global p
268 global k
269 if (str(cvar3.get())==str(results88[k]) or str(cvar1.get())==str(results88[k]) or str(cvar2.get())==str(results88[k])):
270 print("wp")
271 p=p+1
272 print(p)
273 else:
274 print("fufel")
275 k = k + 1
276 root3.destroy()
277 end()
278 button1 = Button(root3, text="NEXT", command=xxx)
279 button1.pack()
280 root3.mainloop()
281def fff():
282 global q
283 global e
284 s1=0
285 conn = sqlite3.connect('228.db')
286 cursor = conn.cursor()
287 cursor.execute('SELECT vopr3 FROM sozd1 ')
288 results34 = cursor.fetchall()
289 print(results34)
290 for j in results34:
291 s1=s1+1
292 if (e>=s1):
293 ddd()
294 if (results34[e] != ('2',) and results34[e] != ('3',)):
295 root4 = Tk()
296 root4.title("моя база3")
297 root4.geometry("1000x1000")
298 cursor.execute('SELECT vopr3 FROM sozd1 ')
299 results34 = cursor.fetchall()
300 cursor.execute('''SELECT otv22 FROM sozd2 ''')
301 results7 = cursor.fetchall()
302 print(results7)
303 cursor.execute('''SELECT otv33 FROM sozd2 ''')
304 results8 = cursor.fetchall()
305 print(results8)
306 cursor.execute('''SELECT otv44 FROM sozd2 ''')
307 results9 = cursor.fetchall()
308 print(results9)
309 cursor.execute('''SELECT prav1 FROM sozd2 ''')
310 results10 = cursor.fetchall()
311 print(results10)
312 lbl1 = Label(root4, text="")
313 lbl1.pack(anchor=W)
314 lbl1['text'] = results34[e]
315 cvar1 = StringVar()
316 cvar1.set(0)
317 c1 = Radiobutton(root4, text=results7[e], value="(1,)", variable=cvar1)
318 c1.pack(anchor=W)
319 c2 = Radiobutton(root4, text=results8[e], value="(2,)", variable=cvar1)
320 c2.pack(anchor=W)
321 c3 = Radiobutton(root4, text=results9[e], value="(3,)", variable=cvar1)
322 c3.pack(anchor=W)
323 label1 = Label(text=str(cvar1.get()))
324 label1.pack()
325 label2 = Label(text=str(cvar1.get()))
326 label2.pack()
327 label3 = Label(text=str(cvar1.get()))
328 label3.pack()
329
330 def skkk(*args):
331 label1.config(text=str(cvar1.get()))
332 label2.config(text=str(cvar1.get()))
333 label3.config(text=str(cvar1.get()))
334
335 cvar1.trace('w', skkk)
336 cvar1.trace('w', skkk)
337 cvar1.trace('w', skkk)
338 else:
339 e=e+1
340 fff()
341 def xxx1():
342 global e
343 global p
344 if (str(cvar1.get())==str(results10[e])):
345 print("wp")
346 p=p+1
347 print(p)
348 else:
349 print("fufel")
350 e = e + 1
351 root4.destroy()
352 fff()
353 button1 = Button(root4, text="NEXT", command=xxx1)
354 button1.pack()
355 root4.mainloop()
356def ddd():
357 global f
358 s2 = 0
359 l=0
360 conn = sqlite3.connect('228.db')
361 cursor = conn.cursor()
362 cursor.execute('SELECT vopr2 FROM sozd1 ')
363 results77 = cursor.fetchall()
364 print("lds")
365 cursor.execute('''SELECT * FROM sozd2''')
366 results78 = cursor.fetchall()
367 print(results78)
368 for l in results77:
369 s2 = s2 + 1
370 if (f >= s2):
371 konec()
372 if (results77[f] != ('2',)):
373 root5 = Tk()
374 root5.title("моя база4")
375 root5.geometry("1000x1000")
376 lbl1 = Label(root5, text="")
377 lbl1.pack(anchor=W)
378 lbl1['text'] = results77[f]
379 textbox77 = Entry(root5, width=50)
380 textbox77.focus_set()
381 textbox77.pack(anchor=W)
382 else:
383 f=f+1
384 ddd()
385 def xxx2():
386 global p
387 global f
388 cursor.execute('''SELECT * FROM sozd2 WHERE otv1 = ?;''', (textbox77.get(),))
389 results21 = cursor.fetchall()
390 if results21!=[]:
391 print("wp")
392 p=p+1
393 else:
394 print("fufel")
395 f=f+1
396 root5.destroy()
397 ddd()
398
399 button1 = Button(root5, text="NEXT", command=xxx2)
400 button1.pack()
401 root5.mainloop()
402def konec():
403 global p
404 global f
405 root6 = Tk()
406 root6.title("konec")
407 root6.geometry("1000x1000")
408 mark = (p / f) * 100
409 print(mark)
410 if mark < 50:
411 lbl44 = Label(root6, text="2")
412 lbl44.pack()
413 if (mark >= 50) and (mark < 75):
414 mark = 3
415 lbl44 = Label(root6, text="3")
416 lbl44.pack()
417 if (mark >= 75) and (mark < 90):
418 mark = 4
419 lbl4 = Label(root6, text="4")
420 lbl4.pack()
421 if (mark >= 90) and (mark < 100):
422 lbl44 = Label(root6, text="5")
423 lbl44.pack()
424 mark = 5
425 root6.mainloop()
426button1 = Button(root, text="Создать тест", command=all)
427button1.pack()
428button = Button(root, text="Пройти тест", command=end)
429button.pack()
430root.mainloop()