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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
| from tkinter import*
import random
from tkinter import messagebox
from tkinter import filedialog
#Окно программы
test_window=Tk()
test_window.title("Тест")
test_window.geometry ('800x600+200+50')
test_window.resizable(width=False, height=False)
results_window=Tk()
results_window.title("Результаты")
results_window.geometry ('600x500+200+50')
results_window.resizable(width=False, height=False)
# Цвет текст
text_color='black'
#Размеры шрифта
button_font=('Arrial',16)
label_font=('Arrial',15)
#Цвета виджетов 1 окна
button_color='#3366FF'
label_color='#66CCFF'
question_label_color='#3399FF'
#Цвета виджетов 2 окна
label2_color='#9966FF'
mian_label2_color='#CC66FF'
not_active_button='#999999'
#Коо виджетов
main_coo_x=0.25
main_coo_y=0.06
coo_end_x=0.89
coo_end_y=0.93
coo_column1_x=0.1
coo_column1_y=0.2
answer_space_x=0.13
answer_space_y=0.1
coo2_column1_x=0.05
coo2_column1_y=0.15
question2_space=0.08
def search_file():
file_name = filedialog.askopenfilename()
return file_name
def string_text(j,user_answers, correct_answers, number):
answers_window.insert(number, ("%-23s%-19s%-18s" % (j,user_answers[j-1], correct_answers[j-1])))
answers_window.insert(number, '\n')
class test ():
def open_files(self):
global questions_namber, order_of_questions, order_of_answers, all_questions, all_answers, answers, p, g_k, correct_answers, lenght_file
if p==0:
question_window.delete(1.0, END)
try:
self=open('Вопросы.txt', 'r')
self=self.readlines()
except FileNotFoundError:
choice = messagebox.askyesno(title='Ошибка', message='Файл не обнаружен. Начать поиск в ручную?')
if choice == True:
file_name=search_file()
self=open(file_name, 'r')
self=self.readlines()
all_list=[]
order_of_questions=[]
order_of_answers=[]
correct_answers=[]
question_namber=0
namber_question_label.place(relx=coo_column1_x, rely=coo_column1_y)
question_window.place(relx=coo_column1_x, rely=coo_column1_y+0.08, relwidth=0.8, relheight=0.15)
Test_question_1.place(relx=coo_column1_x, rely=0.45)
Test_question_2.place(relx=coo_column1_x, rely=0.55)
Test_question_3.place(relx=coo_column1_x, rely=0.65)
Test_question_4.place(relx=coo_column1_x, rely=0.75)
next_question_button.place(relx=0.66, rely=0.85)
end_test_button.place(relx=0.45, rely=0.85)
previous_question_button.place(relx=0.4, rely=0.85)
lenght_file=len(self)
k=0
for i in self:
k=k+1
i=i.replace(' ','_')
i=i.replace(';',' ')
information_line=i.split(' ')
all_list.append(information_line)
while len(order_of_questions)!=10:
r=random.randint(0,9)
if r in order_of_questions:
pass
else:
order_of_questions.append(r)
j=0
answers=[]
all_questions=[]
all_answers=[]
for j in range(k):
a=all_list[j][0].replace('_',' ')
a=a.replace('А.','\nА.')
a=a.replace('Б.','\nБ.')
all_questions.append(a)
a=all_list[j][1].replace('_',' ')
answers.append(a)
a=all_list[j][2].replace('_',' ')
answers.append(a)
a=all_list[j][3].replace('_',' ')
answers.append(a)
a=all_list[j][4].replace('_',' ')
answers.append(a)
all_answers.append(answers)
answers=[]
j=0
for j in range(k):
while len(order_of_answers)!=4:
r=random.randint(1,4)
if r in order_of_answers:
pass
else:
order_of_answers.append(r)
for l in range(4):
if order_of_answers[l]==1:
correct_answers.append(l+1)
answers.append(order_of_answers)
order_of_answers=[]
n_q=order_of_questions[question_namber]
question=all_questions[n_q]
namber_question_label['text']='Вопрос '+str(question_namber+1)
question_window.insert(1.0,question)
n=answers[0][0]-1
Test_question_1['text']=all_answers[n_q][n]
n=answers[0][1]-1
Test_question_2['text']=all_answers[n_q][n]
n=answers[0][2]-1
Test_question_3['text']=all_answers[n_q][n]
n=answers[0][3]-1
Test_question_4['text']=all_answers[n_q][n]
next_question_button['bg']=button_color
start_button['bg']=not_active_button
p=1
g_k=k
else:
mess = messagebox.showwarning(title='Ошибка', message='Тест уже начат.')
if mess == True:
pass
def next_question(self):
global questions_namber, user_answers, c
if questions_namber!= 9:
question_window.delete(1.0, END)
if questions_namber!= 9:
questions_namber+=1
if c==0:
c=1
for j in range(g_k):
user_answers.append(0)
o=var.get()+1
if user_answers[questions_namber-1]!=o:
user_answers[questions_namber-1]=o
n_q=order_of_questions[questions_namber]
question=all_questions[n_q]
namber_question_label['text']='Вопрос '+str(questions_namber+1)
question_window.insert(1.0,question)
n=answers[questions_namber][0]-1
Test_question_1['text']=all_answers[n_q][n]
n=answers[questions_namber][1]-1
Test_question_2['text']=all_answers[n_q][n]
n=answers[questions_namber][2]-1
Test_question_3['text']=all_answers[n_q][n]
n=answers[questions_namber][3]-1
Test_question_4['text']=all_answers[n_q][n]
if questions_namber==9:
next_question_button['bg']=not_active_button
end_test_button['bg']=button_color
if questions_namber!=0:
previous_question_button['bg']=button_color
def previous_question(self):
global questions_namber, user_answers
if questions_namber!= 0:
question_window.delete(1.0, END)
if questions_namber!= 0:
questions_namber-=1
n_q=order_of_questions[questions_namber]
question=all_questions[n_q]
namber_question_label['text']='Вопрос '+str(questions_namber+1)
question_window.insert(1.0,question)
n=answers[n_q][0]-1
Test_question_1['text']=all_answers[n_q][n]
n=answers[n_q][1]-1
Test_question_2['text']=all_answers[n_q][n]
n=answers[n_q][2]-1
Test_question_3['text']=all_answers[n_q][n]
n=answers[n_q][3]-1
Test_question_4['text']=all_answers[n_q][n]
if questions_namber!=9:
next_question_button['bg']=button_color
end_test_button['bg']=not_active_button
if questions_namber==0:
previous_question_button['bg']=not_active_button
def check():
global h
if h!=0:
mess = messagebox.showwarning(title='Ошибка', message='Тест уже завершён.')
if mess == True:
pass
else:
if questions_namber!=9:
mess = messagebox.showwarning(title='Ошибка', message='Тест ещё не завершён. Невозможно проверить ответы.')
if mess == True:
pass
else:
o=var.get()+1
if user_answers[questions_namber]!=o:
user_answers[questions_namber]=o
h=1
correct=0
incorrect=0
j=0
k=g_k
for j in range(k):
if user_answers[j]==correct_answers[j]:
correct+=1
else:
incorrect+=1
answers_window.insert(1.0, 'Номер вопроса Ваш ответ Правильный ответ\n')
j=0
for j in range(k):
number=float(lenght_file)+2
string_text(j+1, user_answers, correct_answers, number)
sr='Коливество правильных ответов: '+str(correct)+'/'+str(correct+incorrect)
res_label['text']=sr
if correct<4:
o_label['text']='Оценка: 2'
elif correct<6:
o_label['text']='Оценка: 3'
elif correct<9:
o_label['text']='Оценка: 4'
else:
o_label['text']='Оценка: 5'
questions_namber=0
user_answers=[]
p=0
c=0
h=0
start_button=Button(test_window, text='Начать тест',font=button_font,bg=button_color, fg=text_color)
start_button.bind('<Button-1>', test.open_files)
start_button.place(relx=0.45, rely=0.11)
name_label=Label(test_window, text='Тест «Структуры данных. Списки в Python»', bg=label_color, fg=text_color,font='Arrial 17')
name_label.place(relx=main_coo_x, rely=main_coo_y)
name_label=Label(test_window, text='Программирование', bg=label_color, fg=text_color,font='Arrial 15')
name_label.place(relx=0.42, rely=0.01)
namber_question_label=Label(test_window, text=' ', bg=question_label_color, fg=text_color,font=label_font)
question_window=Text(test_window, height=15, width=80, wrap="word", fg=text_color, font=('Courier New',14), bd=5)
scroll=Scrollbar(question_window,command=question_window.yview)
scroll.pack(side=RIGHT, fill=Y)
question_window.config(yscrollcommand=scroll.set)
var= IntVar()
var.set(0)
Test_question_1 = Radiobutton(bg=question_label_color, fg=text_color, variable=var, value=0)
Test_question_2 = Radiobutton(bg=question_label_color, fg=text_color, variable=var, value=1)
Test_question_3 = Radiobutton(bg=question_label_color, fg=text_color, variable=var, value=2)
Test_question_4 = Radiobutton(bg=question_label_color, fg=text_color, variable=var, value=3)
#Кнопочка перехода к следующему вопросу
next_question_button=Button(test_window, text='→',font=button_font,bg=not_active_button, fg=text_color, command=test.next_question)
end_test_button=Button(test_window, text='Закончить тест',font=button_font,bg=not_active_button, fg=text_color, command=test.check)
previous_question_button=Button(test_window, text='←',font=button_font,bg=not_active_button, fg=text_color, command=test.previous_question)
results_window.configure(background='#9999FF')
close_button=Button(results_window, command=exit, text='Завершить работу',font=button_font,bg=mian_label2_color, fg=text_color)
close_button.place(relx=0.65, rely=0.85)
results_label=Label(results_window, text='Результаты:', bg=mian_label2_color, fg=text_color,font='Arrial 17')
results_label.place(relx=0.4, rely=0.03)
answers_window=Text(results_window, height=15, width=80, wrap="word", fg=text_color, font=('Courier New',14), bd=5)
answers_window.place(relx=0.03, rely=0.3, relwidth=0.95, relheight=0.5)
res_label=Label(results_window, text='Количество правильных ответов:', bg=mian_label2_color, fg=text_color,font='Arrial 14')
res_label.place(relx=0.05, rely=0.12)
o_label=Label(results_window, text='Оценка:', bg=mian_label2_color, fg=text_color,font='Arrial 14')
o_label.place(relx=0.05, rely=0.2)
test_window.mainloop() |