how to make a multiple choice quiz in python with tkinter

Solutions on MaxInterview for how to make a multiple choice quiz in python with tkinter by the best coders in the world

showing results for - "how to make a multiple choice quiz in python with tkinter"
Noah
23 Jul 2018
1global total
2
3y=0  
4from tkinter import *
5from tkinter import ttk
6n= ttk.Notebook()
7f1= ttk.Frame(n)
8f2= ttk.Frame(n)
9f3= ttk.Frame(n)
10f4= ttk.Frame(n)
11f5= ttk.Frame(n)
12f6= ttk.Frame(n)
13
14window= ttk.Frame(n)
15
16
17def main(x):
18    global total
19    n.add(f1, text="One")
20    n.add(f2, text="Two")
21    n.add(f3, text="Three")
22    n.add(f4, text="Four")
23    n.add(f5, text="Five")
24    n.add(f6, text="Six")
25
26    total= ttk.Label(window, text="0")
27
28
29    Label(f1, text="What is Tkinter?").grid(row=2,column=2)
30    Button(f1, text="Guided User Interface").bind(correct)
31    Button(f1, text="Guided User Interface").grid(row=3,column=1)
32    Button(f1, text="Variable", command=incorrect).grid(row=3,column=2)
33    Button(f1, text="Function", command=incorrect).grid(row=3,column=3)
34
35
36    Label(f2, text="What is Turtle?").grid(row=2,column=2)
37    Button(f2, 
38    text="GuidedUserInterface",command=incorrect2).grid(row=3,column=1)
39    Button(f2, text="Module", command=correct2).grid(row=3,column=2)
40    Button(f2, text="Boolean Value", command=incorrect2).grid(row=3,column=3)
41
42    Label(f3, text="What does the 'Print' command do?").grid(row=2,column=2)
43    Button(f3, text="Creater a window",command=incorrect3).grid(row=3,column=1)
44    Button(f3, text="Show a message in the Python Shell", command=correct3).grid(row=3,column=2)
45    Button(f3, text="Print to the printer", command=incorrect3).grid(row=3,column=3)
46
47    Label(f4, text="What is the moniter?").grid(row=2,column=2)
48    Button(f4, text="A display that shows what the computer is doing",command=correct4).grid(row=3,column=1)
49    Button(f4, text="A circut board", command=incorrect4).grid(row=3,column=2)
50    Button(f4, text="A Program", command=incorrect4).grid(row=3,column=3)
51
52
53    Label(f5, text="What does the 'from ____ import' command do?").grid(row=2,column=2)
54    Button(f5, text="Import an image",command=incorrect5).grid(row=3,column=1)
55    Button(f5, text="Import text", command=incorrect5).grid(row=3,column=2)
56    Button(f5, text="Import a module", command=correct5).grid(row=3,column=3)
57
58    Label(f6, text="Which of these is a Boolean Value?").grid(row=2,column=2)
59    Button(f6, text="Enter",command=incorrect6).grid(row=3,column=1)
60    Button(f6, text="Esc", command=incorrect6).grid(row=3,column=2)
61    Button(f6, text="True", command=correct6).grid(row=3,column=3)
62    return total
63
64
65
66def correct():
67    global total
68    Label(f1, text="Correct").grid(row=1,column=2)
69    counter()
70def incorrect():
71    Label(f1, text="Incorrect").grid(row=1,column=2)
72
73def correct2():
74    global total
75    Label(f2, text="Correct").grid(row=1,column=2)
76    counter()
77
78def incorrect2():
79    Label(f2, text="Incorrect").grid(row=1,column=2)
80
81def correct3():
82    global total
83    Label(f3, text="Correct").grid(row=1,column=2)
84    counter()
85
86def incorrect3():
87    Label(f3, text="Incorrect").grid(row=1,column=2)
88
89def correct4():
90    global total
91    Label(f4, text="Correct").grid(row=1,column=2)
92    counter()
93
94def incorrect4():
95    Label(f4, text="Incorrect").grid(row=1,column=2)
96
97def correct5():
98    global total
99    Label(f5, text="Correct").grid(row=1,column=2)
100    counter()
101
102def incorrect5():
103    Label(f5, text="Incorrect").grid(row=1,column=2)
104
105def correct6():
106    global total
107    Label(f6, text="Correct").grid(row=1,column=2)
108    counter()
109
110def incorrect6():
111    Label(f6, text="Incorrect").grid(row=1,column=2)
112
113
114def counter():
115    global total
116    total['text'] = str(int(total['text']) + 1)
117
118
119main(y)
120
121
122n.pack()
123
124n.mainloop()