Skip to content

Commit 96e7285

Browse files
committed
gui impolementation, oop paradigm
1 parent d796ae9 commit 96e7285

File tree

1 file changed

+144
-32
lines changed

1 file changed

+144
-32
lines changed
Lines changed: 144 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,144 @@
1-
print('Welcome to the Hacktoberfest 2022 Quiz')
2-
answer=input('Are you ready to play the Quiz ? (yes/no) :')
3-
score=0
4-
total_questions=3
5-
6-
if answer.lower()=='yes':
7-
answer=input('Question 1: What programming language was this quiz created in?')
8-
if answer.lower()=='python':
9-
score += 1
10-
print('correct')
11-
else:
12-
print('Wrong Answer :(')
13-
14-
15-
answer=input('Question 2: Is one of the values of Hacktoberfest 2022 "EVERYONE IS WELCOME" ? ')
16-
if answer.lower()=='yes':
17-
score += 1
18-
print('correct')
19-
else:
20-
print('Wrong Answer :(')
21-
22-
answer=input('Question 3: Does Hacktoberfest end on December 31?')
23-
if answer.lower()=='no':
24-
score += 1
25-
print('correct')
26-
else:
27-
print('Wrong Answer :(')
28-
29-
print('Thankyou for Playing the Hacktoberfest quiz game, you attempted',score,"questions correctly!")
30-
mark=(score/total_questions)*100
31-
print('Marks obtained:',mark)
32-
print('BYE!')
1+
from tkinter import *
2+
from tkinter import ttk
3+
4+
root = Tk()
5+
6+
root.geometry("500x500")
7+
8+
root.title("Hacktoberfest Quiz")
9+
10+
11+
label = Label(root,text="Hacktoberfest Quiz ",width = 20,height=4,font=("algerian",15))
12+
label.pack()
13+
14+
class Quiz:
15+
print('Welcome to the Hacktoberfest 2022 Quiz')
16+
score=0
17+
total_questions=4
18+
19+
def __init__(self):
20+
# self.ask_question()
21+
pass
22+
23+
def ask_question(self):
24+
answer=input('Are you ready to play the Quiz ? (yes/no) :')
25+
26+
if answer.lower()=='yes':
27+
answer=input('Question 1: What programming language was this quiz created in? Hint: Java, C++, Python')
28+
if answer.lower()=='python':
29+
self.score += 1
30+
print('correct')
31+
else:
32+
print('Wrong Answer :(')
33+
34+
35+
answer=input('Question 2: Is one of the values of Hacktoberfest 2022 "EVERYONE IS WELCOME" ? ')
36+
if answer.lower()=='yes':
37+
self.score += 1
38+
print('correct')
39+
else:
40+
print('Wrong Answer :(')
41+
42+
answer=input('Question 3: Does Hacktoberfest end on December 31?')
43+
if answer.lower()=='no':
44+
self.score += 1
45+
print('correct')
46+
else:
47+
print('Wrong Answer :(')
48+
49+
answer=input('Question 3: Does Hacktoberfest have a discord server?')
50+
if answer.lower()=='yes':
51+
self.score += 1
52+
print('correct')
53+
else:
54+
print('Wrong Answer :(')
55+
56+
print('Thankyou for Playing the Hacktoberfest quiz game, you attempted',self.score,"questions correctly!")
57+
mark=(self.score/self.total_questions)*100
58+
print('Marks obtained:',mark)
59+
print('BYE!')
60+
61+
def evaluate(self):
62+
question_one_value = question_one.get()
63+
if question_one_value.lower()=='python':
64+
self.score += 1
65+
print('correct')
66+
else:
67+
print('Wrong Answer1')
68+
print('correct answer is python ')
69+
70+
question_two_value = question_two.get()
71+
if question_two_value.lower()=='yes':
72+
self.score += 1
73+
print('correct')
74+
else:
75+
print('Wrong Answer2')
76+
print('correct answer is yes ')
77+
78+
question_three_value = question_three.get()
79+
if question_three_value.lower()=='no':
80+
self.score += 1
81+
print('correct')
82+
else:
83+
print('Wrong Answer3')
84+
print('correct answer is no ')
85+
86+
question_four_value = question_four.get()
87+
if question_four_value.lower()=='yes':
88+
self.score += 1
89+
print('correct')
90+
else:
91+
print('Wrong Answer4')
92+
print('correct answer is yes ')
93+
94+
95+
96+
97+
quiz = Quiz()
98+
99+
w1_label = Label(root,text="Question 1: What programming language was this quiz created in? Hint: Java, C++, Python ?",font=("arial",10),width=100,height=4)
100+
w1_label.pack()
101+
question_one = ttk.Combobox(root,value=["Pyhon","Java","C++"])
102+
question_one.current(0)
103+
question_one.pack()
104+
105+
w1_label = Label(root,text="",font=("arial",10),width=100,height=4)
106+
w1_label.pack()
107+
108+
w2_label = Label(root,text="Question 2: Is one of the values of Hacktoberfest 2022 'EVERYONE IS WELCOME' ?",font=("arial",10),width=100,height=4)
109+
w2_label.pack()
110+
question_two = ttk.Combobox(root,value=["Yes","No"])
111+
question_two.current(0)
112+
question_two.pack()
113+
114+
w2_label = Label(root,text="",font=("arial",10),width=100,height=4)
115+
w2_label.pack()
116+
117+
118+
w3_label = Label(root,text="Question 3: Does Hacktoberfest end on December 31?",font=("arial",10),width=100,height=4)
119+
w3_label.pack()
120+
question_three = ttk.Combobox(root,value=["Yes","No"])
121+
question_three.current(0)
122+
question_three.pack()
123+
124+
w3_label = Label(root,text="",font=("arial",10),width=100,height=4)
125+
w3_label.pack()
126+
127+
w4_label = Label(root,text="Question 4: Does Hacktoberfest have a discord server?",font=("arial",10),width=50,height=4)
128+
w4_label.pack()
129+
question_four = ttk.Combobox(root,value=["Yes","No"])
130+
question_four.current(0)
131+
question_four.pack()
132+
133+
w4_label = Label(root,text="",font=("arial",10),width=50,height=4)
134+
w4_label.pack()
135+
136+
137+
button = Button(root,text="Submit",font=("bell mt",10), command=quiz.evaluate)
138+
button.pack()
139+
140+
141+
142+
143+
144+
root.mainloop()

0 commit comments

Comments
 (0)