-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14. Create Radiobutton App.py
59 lines (44 loc) · 1.63 KB
/
14. Create Radiobutton App.py
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
import tkinter as tk
root = tk.Tk()
root.title("CodingPrivacy")
root.geometry("300x200")
questions_with_answers = {
1: {
'question_title': "What is the name of this channel?",
'question_options': ['CodingPrivacy', 'PrivacyCoding'],
'correct_option': 'CodingPrivacy'
},
2: {
'question_title': "What are we learning today?",
'question_options': ['Radio Button', 'Check Button'],
'correct_option': 'Radio Button'
}
}
result = tk.StringVar()
for question_obj in questions_with_answers:
title = questions_with_answers[question_obj]['question_title']
options = questions_with_answers[question_obj]['question_options']
answer = questions_with_answers[question_obj]['correct_option']
var = tk.StringVar()
var.set("null")
label = tk.Label(root, text=title)
label.pack(padx=50, anchor='w')
for i in options:
option = tk.Radiobutton(root, text=i, variable=var, value=i)
option.pack(padx=50, anchor='w')
questions_with_answers[question_obj]['submission'] = var
label = tk.Label(root, textvariable=result)
label.pack(padx=50, anchor='w')
def radio_logic():
flag = 0
for question_obj in questions_with_answers:
submission = questions_with_answers[question_obj]['submission']
if questions_with_answers[question_obj]['correct_option'] != submission.get():
flag = 1
if flag == 1:
result.set("Any one of the answer is incorrect")
else:
result.set("Congrats! all the answers are correct")
button = tk.Button(root, text="Submit", command=radio_logic)
button.pack(padx=50, anchor='w')
root.mainloop()