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