Mar-01-2021, 05:38 PM
Because you got all the answers wrong. Actually you got all the answers wrong twice.
From your code:
Your second problem is you don't wait for the questions to be answered. Your program tests the answer as soon as the widgets are made. None of the OptionMenus are set at this time, so options.get() returns 0.
You need to wait until all the questions are answered before you can calculate the score. This means you'll need a different "options" StringVar() for each question, and you only "get()" the answers from those options when you press the button to continue.
From your code:
options = StringVar(newWindow) ho2=OptionMenu(newWindow,options, "A","B","C","D") ho2.config(bg="dark red",fg="white",width=10,height=1) ho2.place(x=305,y=205) if options=="C": hscore2=1 else: hscore2=0This creates an OptionMenu and binds it to a StringVar(). So far, so good. But then it tries to test the value of the StringVar() and that is where you are twice wrong. First off, to get the value selected by the OptionMenu you use options.get(). options is a StringVar and it is never going to match "C". options.get() may match "C", but not until you fix your other problem.
Your second problem is you don't wait for the questions to be answered. Your program tests the answer as soon as the widgets are made. None of the OptionMenus are set at this time, so options.get() returns 0.
You need to wait until all the questions are answered before you can calculate the score. This means you'll need a different "options" StringVar() for each question, and you only "get()" the answers from those options when you press the button to continue.