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