Project Quizstar
Project Quizstar
import json
import tkinter
import random
import hangman
# questions = [
#]
# answers_choice = [
# ["23","32","33","43",],
# ["get()","input()","gets()","scan()",],
# ["Mumbai","Delhi","Chennai","Lucknow",],
# ["custom location","end","center","beginning",],
# ["Bengluru","Kochin","Mumbai","vishakhapatnam",],
# ["perl","css","python","java",],
# ["function","void","fun","def",],
# ["all","var","let","global",],
#]
# load questions and answer choices from json file instead of the file
data = json.load(f)
answers = [1,1,1,1,3,1,0,1,3,3]
user_answer = []
indexes = []
def nxt():
create()
def gen():
global indexes
x = random.randint(0,9)
if x in indexes:
continue
else:
indexes.append(x)
def showresult(score):
lblQuestion.destroy()
r1.destroy()
r2.destroy()
r3.destroy()
r4.destroy()
labelimage = Label(
root,
background = "#ffffff",
border = 0,
labelimage.pack(pady=(50,30))
labelresulttext = Label(
root,
font = ("Consolas",16),
background = "#ffffff",
labelresulttext.pack()
labelimage.configure(image=img)
labelimage.image = img
img = PhotoImage(file="ok.png")
labelimage.configure(image=img)
labelimage.image = img
else:
img = PhotoImage(file="bad.png")
labelimage.configure(image=img)
labelimage.image = img
nxt()
def calc():
global indexes,user_answer,answers
x=0
score = 0
for i in indexes:
if user_answer[x] == answers[i]:
score = score + 5
x += 1
print(score)
showresult(score)
ques = 1
def selected():
global radiovar,user_answer
global lblQuestion,r1,r2,r3,r4
global ques
x = radiovar.get()
user_answer.append(x)
radiovar.set(-1)
if ques < 5:
lblQuestion.config(text= questions[indexes[ques]])
r1['text'] = answers_choice[indexes[ques]][0]
r2['text'] = answers_choice[indexes[ques]][1]
r3['text'] = answers_choice[indexes[ques]][2]
r4['text'] = answers_choice[indexes[ques]][3]
ques += 1
else:
# print(indexes)
# print(user_answer)
def startquiz():
global lblQuestion,r1,r2,r3,r4
lblQuestion = Label(
root,
text = questions[indexes[0]],
width = 500,
justify = "center",
wraplength = 400,
background = "#ffffff",
lblQuestion.pack(pady=(100,30))
global radiovar
radiovar = IntVar()
radiovar.set(-1)
r1 = Radiobutton(
root,
text = answers_choice[indexes[0]][0],
variable = radiovar,
command = selected,
background = "#ffffff",
r1.pack(pady=5)
r2 = Radiobutton(
root,
text = answers_choice[indexes[0]][1],
value = 1,
variable = radiovar,
command = selected,
background = "#ffffff",
r2.pack(pady=5)
r3 = Radiobutton(
root,
text = answers_choice[indexes[0]][2],
value = 2,
variable = radiovar,
command = selected,
background = "#ffffff",
)
r3.pack(pady=5)
r4 = Radiobutton(
root,
text = answers_choice[indexes[0]][3],
value = 3,
variable = radiovar,
command = selected,
background = "#ffffff",
r4.pack(pady=5)
def startIspressed():
labelimage.destroy()
labeltext.destroy()
lblInstruction.destroy()
lblRules.destroy()
btnStart.destroy()
gen()
startquiz()
root = tkinter.Tk()
root.title("Quizstar")
root.geometry("700x600")
root.config(background="#ffffff")
root.resizable(0,0)
img1 = PhotoImage(file="transparentGradHat.png")
labelimage = Label(
root,
image = img1,
background = "#ffffff",
labelimage.pack(pady=(40,0))
labeltext = Label(
root,
text = "Quizstar",
background = "#ffffff",
labeltext.pack(pady=(0,50))
img2 = PhotoImage(file="Frame.png")
btnStart = Button(
root,
image = img2,
relief = FLAT,
border = 0,
command = startIspressed,
btnStart.pack()
lblInstruction = Label(
root,
text = "Read The Rules And\nClick Start Once You Are ready",
background = "#ffffff",
font = ("Consolas",14),
justify = "center",
lblInstruction.pack(pady=(10,100))
lblRules = Label(
root,
text = "This quiz contains 10 questions\nYou will get 20 seconds to solve a question\nOnce you
select a radio button that will be a final choice\nhence think before you select",
width = 100,
font = ("Times",14),
background = "#000000",
foreground = "#FACA2F",
lblRules.pack()
root.mainloop()