I want my quiz to wait for user interactions with the buttons of different values and then decide if the "text" inside the button matches the answer to the question, This system works but instead of waiting for the user to pick one option. It goes through all the questions outputting all the answers and questions, doesn't require interactions.
I tried to use partial
and lambda
to make it go to the function after the user pressed something and it works but it doesn't accept button presses and goes through every question. And threading basically does the same thing but stays at the first question and shows a million popups of every option without user interaction.
Is there an easier way of doing this and allow the function to see what button was pressed or am I doing it right?
listofdifnumbers
contains all the question numbers for difficulties so let's say the user picked 10 easy, 20 normal, and 30 hard questions then listofdifnumbers
will be [10,20,30]
.
questions
contains all the questions in the form of a nested dictionary, E.g. {1: {'Question': 'WWW stands for?', 'fakes': 'World Word Web', 'Answer': 'World Wide Web'}, 2: {'Question': 'Which of the following is a group of independent computers attached to one another through communication media', 'fakes': 'Internet', 'Answer': 'Network'}}
def wrongcheck(num):
global Questionnum, questionseasy1, questionsmedium1, questionshard1,answer,score
global choice, correctorwrong
global score1of1
if score1of1<=listofdifnumbers[0]:
if num == 1:
if showeasybutton1["text"]== questions[score1of1].get("Answer"):
picked = showeasybutton1["text"]
choice.append(picked)
correctorwrong.append("correct")
error.showerror("Correct",("%s is the correct answer \n Welldone \n Score +1"%(picked)),icon="info")
score+=1
else:
picked = showeasybutton1["text"]
choice.append(picked)
correctorwrong.append("Wrong")
error.showerror("Wrong",("%s was the correct answer,\n You chose %s"%(questions[score1of1].get("Answer"),picked)),icon="info")
elif num == 2:
if showeasybutton2["text"]== questions[score1of1].get("Answer"):
picked = showeasybutton2["text"]
choice.append(picked)
correctorwrong.append("correct")
error.showerror("Correct",("%s is the correct answer \n Welldone \n Score +1"%(picked)),icon="info")
score+=1
else:
picked = showeasybutton2["text"]
choice.append(picked)
correctorwrong.append("Wrong")
error.showerror("Wrong",("%s was the correct answer,\n You chose %s"%(questions[score1of1].get("Answer"),picked)),icon="info")
print(correctorwrong)
print(choice)
print(score1of1)
def quizinterfacestarter():
global timer
global login
global login, lookwhereat2,quizconfigurationframe, AllquizSTATSlabel
global Questionnum, questionseasy1, questionsmedium1, questionshard1, MaxMarkss, MaxMarks
global questions
print(questions)
print(len(questions))
screen_width = login.winfo_screenwidth()
screen_height = login.winfo_screenheight()
for widget in login.winfo_children():
widget.destroy()
height1 = int(screen_height)/4
height2 = int(screen_height)*3
tophalfframe= Frame(login,width=int(screen_width),height=height1,bg="light coral")
tophalfframe.grid(sticky="new")
goback= PhotoImage(file='icons/goback.png')
exitframebutton= Button(tophalfframe,image=goback,text="Return ",compound="left",bg='aquamarine',relief='flat', font="Ariel 25",command=subjectgoback)
exitframebutton.grid(column=1,sticky="nws")
movealonglabel = Label(text=" ",bg="light coral")
movealonglabel.grid(row=1,column=2,columnspan=2)
QuestionLabelAsker = Label(tophalfframe,text="Questions Loading ...",relief='raised', font="Ariel 20")
QuestionLabelAsker.grid(column=5,row=1,columnspan=7)
if timer == True:
initiatetimerstart = time.strftime("%H:%M:%S")
global fsos,showeasybutton1,showeasybutton2,answer
showeasybutton1=Button(login,text="Answer 1",font="Ariel 30")
showeasybutton1.grid(sticky="new")
showeasybutton2=Button(login,text="Answer 2",font="Ariel 30")
showeasybutton2.grid(sticky="new")
showmediumbutton=Button(login,text="Answer 3",font="Ariel 30")
showmediumbutton.grid(sticky="new")
showhardbutton=Button(login,text="Answer 4",font="Ariel 30")
showhardbutton.grid(sticky="new")
global choice, correctorwrong,score
choice = []
correctorwrong =[]
score=0
sonumisone=0
global score1of1
score1of1=0
##works up to here
while sonumisone != (sum(listofdifnumbers)+1):
sonumisone+=1
if sonumisone<=listofdifnumbers[0]:
score1of1+=1
QuestionLabelAsker["text"]=questions[score1of1].get("Question")
answers = [questions[score1of1].get("fakes"),questions[score1of1].get("Answer")]
fsos = r.choice(answers)
showeasybutton1["text"]= fsos
answers.remove(fsos)
showeasybutton2["text"]= answers[0]
showeasybutton2.config(command=lambda *args: wrongcheck(2))
showeasybutton1.config(command=lambda *args: wrongcheck(1))
showmediumbutton["state"]="disabled"
showhardbutton["state"]="disabled"
login.mainloop()