· 6 years ago · Jun 06, 2019, 08:28 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="Введите номер верного ответа 1:")
37 lbl4.pack()
38 textbox7 = Entry(root3, width=30)
39 textbox7.pack()
40 lbl4 = Label(root3, text="Введите номер верного ответа 2:")
41 lbl4.pack()
42 textbox8 = Entry(root3, width=30)
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=30)
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
192 button2 = Button(root2, text="checkbutton", command=a2)
193 button2.pack()
194 button2 = Button(root2, text="textbox", command=a1)
195 button2.pack()
196 button2 = Button(root2, text="radipbutton", command=a3)
197 button2.pack()
198 def al():
199 root2.destroy()
200 prog()
201 button2 = Button(root2, text="ok", command=al)
202 button2.pack()
203 root.destroy()
204
205 global k
206 k = 0
207 global f
208 f = 0
209 global p
210 p = 0
211 global e
212 e = 0
213 global w
214 w=0
215
216 def end():
217 global k
218 if k == 0:
219 root.destroy()
220 s = 0
221 conn = sqlite3.connect('1228.db')
222 cursor = conn.cursor()
223 cursor.execute('SELECT vopr FROM sozd1 ')
224 results3 = cursor.fetchall()
225 for i in results3:
226 s=s+1
227 if (k>=s):
228 fff()
229 if (results3[k] != ('2',)):
230 root3 = Tk()
231 root3.title("моя база2")
232 root3.geometry("350x350")
233 cursor.execute('SELECT vopr3 FROM sozd1 ')
234 results34 = cursor.fetchall()
235 print(results34)
236 cursor.execute('''SELECT otv2 FROM sozd2 ''')
237 results4 = cursor.fetchall()
238 cursor.execute('''SELECT otv3 FROM sozd2 ''')
239 results5 = cursor.fetchall()
240 cursor.execute('''SELECT otv4 FROM sozd2 ''')
241 results6 = cursor.fetchall()
242 cursor.execute('''SELECT otv22 FROM sozd2 ''')
243 results7 = cursor.fetchall()
244 cursor.execute('''SELECT otv33 FROM sozd2 ''')
245 results8 = cursor.fetchall()
246 cursor.execute('''SELECT otv44 FROM sozd2 ''')
247 cursor.execute('''SELECT prav FROM sozd2 ''')
248 results88 = cursor.fetchall()
249 cursor.execute('''SELECT prav0 FROM sozd2 ''')
250 results89 = cursor.fetchall()
251 lbl1 = Label(root3, text="")
252 lbl1.pack(anchor=W)
253 lbl1['text'] = results3[k]
254 cvar1 = StringVar()
255 cvar1.set(0)
256 c1 = Checkbutton(root3, text=results4[k], variable=cvar1, onvalue="(1,)", offvalue=0)
257 c1.pack(anchor=W)
258 cvar2 = StringVar()
259 cvar2.set(0)
260 c2 = Checkbutton(root3, text=results5[k], variable=cvar2, onvalue="(2,)", offvalue=0)
261 c2.pack(anchor=W)
262 cvar3 = StringVar()
263 cvar3.set(0)
264 c3 = Checkbutton(root3, text=results6[k], variable=cvar3, onvalue="(3,)", offvalue=0)
265 c3.pack(anchor=W)
266
267 def skk(*args):
268 label1.config(text=str(cvar1.get()))
269 label2.config(text=str(cvar2.get()))
270 label3.config(text=str(cvar3.get()))
271
272 cvar1.trace('w', skk)
273 cvar2.trace('w', skk)
274 cvar3.trace('w', skk)
275 else:
276 k=k+1
277 end()
278
279 def xxx():
280 global p
281 global k
282 if str(cvar1.get())==str(results88[k]) or str(cvar1.get())==str(results89[k]):
283 print("wp")
284 p=p+0.5
285 print(p)
286 if str(cvar2.get())==str(results88[k]) or str(cvar2.get())==str(results89[k]):
287 print("wp")
288 p=p+0.5
289 print(p)
290 if str(cvar3.get())==str(results88[k]) or str(cvar3.get())==str(results89[k]):
291 print("wp")
292 p=p+0.5
293 print(p)
294 if (p<w+1):
295 p=p-0.5
296 print("fufel")
297 print(p)
298 k = k + 1
299 root3.destroy()
300 end()
301 button1 = Button(root3, text="NEXT", command=xxx)
302 button1.pack()
303 root3.mainloop()
304 def fff():
305 global q
306 global e
307 s1=0
308 conn = sqlite3.connect('1228.db')
309 cursor = conn.cursor()
310 cursor.execute('SELECT vopr3 FROM sozd1 ')
311 results34 = cursor.fetchall()
312 print(results34)
313 for j in results34:
314 s1=s1+1
315 if (e>=s1):
316 ddd()
317 if (results34[e] != ('2',) and results34[e] != ('3',)):
318 root4 = Tk()
319 root4.title("моя база3")
320 root4.geometry("350x350")
321 cursor.execute('SELECT vopr3 FROM sozd1 ')
322 results34 = cursor.fetchall()
323 cursor.execute('''SELECT otv22 FROM sozd2 ''')
324 results7 = cursor.fetchall()
325 print(results7)
326 cursor.execute('''SELECT otv33 FROM sozd2 ''')
327 results8 = cursor.fetchall()
328 print(results8)
329 cursor.execute('''SELECT otv44 FROM sozd2 ''')
330 results9 = cursor.fetchall()
331 print(results9)
332 cursor.execute('''SELECT prav1 FROM sozd2 ''')
333 results10 = cursor.fetchall()
334 print(results10)
335 lbl1 = Label(root4, text="")
336 lbl1.pack(anchor=W)
337 lbl1['text'] = results34[e]
338 cvar1 = StringVar()
339 cvar1.set(0)
340 c1 = Radiobutton(root4, text=results7[e], value="(1,)", variable=cvar1)
341 c1.pack(anchor=W)
342 c2 = Radiobutton(root4, text=results8[e], value="(2,)", variable=cvar1)
343 c2.pack(anchor=W)
344 c3 = Radiobutton(root4, text=results9[e], value="(3,)", variable=cvar1)
345 c3.pack(anchor=W)
346 def skkk(*args):
347 label1.config(text=str(cvar1.get()))
348 label2.config(text=str(cvar1.get()))
349 label3.config(text=str(cvar1.get()))
350
351 cvar1.trace('w', skkk)
352 cvar1.trace('w', skkk)
353 cvar1.trace('w', skkk)
354 else:
355 e=e+1
356 fff()
357 def xxx1():
358 global e
359 global p
360 global w
361 if (str(cvar1.get())==str(results10[e])):
362 print("wp")
363 p=p+1
364 w=w+1
365 print(p)
366 else:
367 print("fufel")
368 e = e + 1
369 root4.destroy()
370 fff()
371 button1 = Button(root4, text="NEXT", command=xxx1)
372 button1.pack()
373 root4.mainloop()
374 def ddd():
375 global f
376 s2 = 0
377 l=0
378 conn = sqlite3.connect('1228.db')
379 cursor = conn.cursor()
380 cursor.execute('SELECT vopr2 FROM sozd1 ')
381 results77 = cursor.fetchall()
382 print("lds")
383 cursor.execute('''SELECT * FROM sozd2''')
384 results78 = cursor.fetchall()
385 print(results78)
386 for l in results77:
387 s2 = s2 + 1
388 if (f >= s2):
389 konec()
390 if (results77[f] != ('2',)):
391 root5 = Tk()
392 root5.title("моя база4")
393 root5.geometry("350x350")
394 lbl1 = Label(root5, text="")
395 lbl1.pack(anchor=W)
396 lbl1['text'] = results77[f]
397 textbox77 = Entry(root5, width=50)
398 textbox77.focus_set()
399 textbox77.pack(anchor=W)
400 else:
401 f=f+1
402 ddd()
403 def xxx2():
404 global p
405 global f
406 global w
407 cursor.execute('''SELECT * FROM sozd2 WHERE otv1 = ?;''', (textbox77.get(),))
408 results21 = cursor.fetchall()
409 if results21!=[]:
410 print("wp")
411 p=p+1
412 w=w+1
413 else:
414 print("fufel")
415 f=f+1
416 root5.destroy()
417 ddd()
418
419 button1 = Button(root5, text="NEXT", command=xxx2)
420 button1.pack()
421 root5.mainloop()
422 def konec():
423 global p
424 global f
425 root6 = Tk()
426 root6.title("konec")
427 root6.geometry("500x500")
428 mark = (p / f) * 100
429 print(mark)
430 if p<0:
431 p=0
432 if mark < 50:
433 lbl44 = Label(root6, text="2",width=10,height=7,font="Arial 100",fg="red")
434 lbl44.pack()
435 if (mark >= 50) and (mark < 75):
436 mark = 3
437 lbl44 = Label(root6, text="3",width=10,height=7,font="Arial 100",fg="red")
438 lbl44.pack()
439 if (mark >= 75) and (mark < 90):
440 mark = 4
441 lbl4 = Label(root6, text="4",width=10,height=7,font="Arial 100",fg="green")
442 lbl4.pack()
443 if (mark >= 90) and (mark <= 100):
444 lbl44 = Label(root6, text="5",width=10,height=7,font="Arial 100",fg="green" )
445 lbl44.pack()
446 mark = 5
447 lbl45 = Label(root6, text="Вы ответили правльно на")
448 lbl45 .place(relx=0.1, rely=0.7)
449 lbl46 = Label(root6, text=p)
450 lbl46 .place(relx=0.40, rely=0.7)
451 lbl47 = Label(root6, text="вопросов")
452 lbl47 .place(relx=0.50, rely=0.7)
453 lbl48 = Label(root6, text="из")
454 lbl48 .place(relx=0.63, rely=0.7)
455 lbl49 = Label(root6, text=f)
456 lbl49 .place(relx=0.67, rely=0.7)
457 root6.mainloop()
458 def clear():
459 conn = sqlite3.connect('1228.db')
460 cursor = conn.cursor()
461 cursor.execute('''DROP TABLE sozd1''')
462 cursor.execute('''DROP TABLE sozd2''')
463 button1 = Button(root, text="Создать тест", command=all)
464 button1.pack()
465 button = Button(root, text="Пройти тест", command=end)
466 button.pack()
467 button1 = Button(root, text="clear", command=clear)
468 button1.pack()
469 root.mainloop()
470prog()